Python·100 questions

How to work with files?

Answer
with open('file.txt', 'r', encoding='utf-8') as f:.
f.read() or for line in f:.
Modes: r, w, a, rb.
with automatically closes the file.
pathlib.Path — modern approach.
Was this answer helpful?

More questions in this topic

Related questions from other topics