Reading and Writing Files in Python — a practical guide to Python read write file with clear examples you can reuse in real projects.
Python Tutorial Series (40/95). Prefer one article? Read the complete Python tutorial.
Short description
Choose modes carefully: `r`, `w`, `a`, `rb`, `wb`. Use encoding for text files.
Read and append
with open('notes.txt', 'r', encoding='utf-8') as f:
print(f.read())
with open('notes.txt', 'a', encoding='utf-8') as f:
f.write('Another linen')