File Handling in Python
File handling is reading and writing disk files. open(path, mode) with "r" read, "w" write (erases existing), "a" append, "rb" binary. Prefer with open(...) as f: so the file closes even if an error happens. read(), readline(), readlines() for input. write() / writelines() for output.
Trap: "w" on a marks file you meant to read — content gone. Always mention with in the viva. Then one tiny write of "Asha,90\n" and read it back.
File Handling in Python — output: Asha then Pune. StringIO is the same read pattern as a real file, and this script always runs.
with open(...) as f
│ read / write
▼
auto closewith open as best practice.