Last active
June 19, 2021 08:47
-
-
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").
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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