Python Tutorial · Revision notes

Python File Handling

File handling lets programs read and write persistent data. Python offers open() with modes, the with statement for safe cleanup, and standard-library or third-party modules for CSV, JSON and Excel files.

Quick revision

  • r, w, a, x, +, b, t are the file mode letters.
  • with open(...) closes the file automatically.
  • csv: use newline="", DictReader/DictWriter; values are strings.
  • json: dumps/loads for strings, dump/load for files.
  • Excel: openpyxl for cells and styles, pandas for DataFrames.
Read the full Python File Handling notes on Doubtclip →