Skip to content

Instantly share code, notes, and snippets.

@wantyapps
Last active June 19, 2021 08:47
Show Gist options
  • Save wantyapps/d6dae7e7bb423b6a53afb8e1e00a66c5 to your computer and use it in GitHub Desktop.
Save wantyapps/d6dae7e7bb423b6a53afb8e1e00a66c5 to your computer and use it in GitHub Desktop.
Read a file, and print the content of it without \n after line (Remember to replace "<yourfile>.<yourext>" with the file and its extension. Example: "hello.txt").
try:
with open("<yourfilename>.<yourext>", "r") as f:
for line in f:
print(line.replace("\n", "")
except FileNotFoundError:
# If the file does not exist, print:
print("File not found.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment