3/10 Read file
<..>
Reading is mostly straightforward with r
flag. You may need to define encoding, e.g. for utf-8 encoding="utf-8"
Read
Ideally it's something like this:
with open('filename.txt', 'r', encoding="utf-8") as f:
for line in f:
print(line)
or basic (no with
, no encoding
):
f = open("filename.txt", 'r')
for line in f:
print(line)
f.close()
Other
Python docs: here
No Comments