Affiliate disclosure
Book titles on this page link to Amazon. As an Amazon Associate, DataField.Dev earns from qualifying purchases — at no additional cost to you.
Further Reading: File Input and Output
Python Documentation
-
Built-in Functions:
open()(Tier 1) https://docs.python.org/3/library/functions.html#open The authoritative reference for all file modes, encoding options, and buffering behavior. Bookmark this page — you'll return to it often. -
pathlib— Object-oriented filesystem paths (Tier 1) https://docs.python.org/3/library/pathlib.html Complete documentation for thePathclass. The "Correspondence to tools in theosmodule" table is particularly useful when translating older code that usesos.path. -
csv— CSV File Reading and Writing (Tier 1) https://docs.python.org/3/library/csv.html Coversreader,writer,DictReader,DictWriter, dialects, and formatting parameters. The "Dialects and Formatting Parameters" section is essential when you encounter CSV files that use semicolons, tabs, or other non-standard delimiters. -
json— JSON encoder and decoder (Tier 1) https://docs.python.org/3/library/json.html Coversdump,load,dumps,loads, and customization viaJSONEncoder/JSONDecodersubclasses. The "Standard Compliance" section explains edge cases in JSON parsing.
Tutorials and Guides
-
Real Python: "Reading and Writing Files in Python (Guide)" (Tier 1) https://realpython.com/read-write-files-python/ A thorough, beginner-friendly walkthrough of file I/O in Python. Covers topics this chapter touches on (modes, context managers, encoding) plus additional topics like binary files and the
iomodule. -
Real Python: "Working With Files in Python" (Tier 1) https://realpython.com/working-with-files-in-python/ Focuses on file system operations — listing directories, copying files, archiving. Good complement to this chapter's
pathlibsection. -
Real Python: "Reading and Writing CSV Files in Python" (Tier 1) https://realpython.com/python-csv/ Detailed CSV guide covering edge cases like files with different delimiters, handling Unicode in CSV, and using
pandasfor large CSV files (a preview of tools you'll encounter in data science courses).
Data Formats
-
JSON.org: "Introducing JSON" (Tier 1) https://www.json.org/json-en.html The official JSON specification — one of the shortest and most elegant specs in all of computing. The entire format is defined by a single page of railroad diagrams. Worth reading to understand just how simple JSON really is.
-
RFC 4180: "Common Format and MIME Type for CSV Files" (Tier 2) https://tools.ietf.org/html/rfc4180 The closest thing CSV has to an official specification. Despite being widely used, CSV was never formally standardized until this RFC, and even this is technically "informational" rather than a full standard. The lack of a strict standard is why CSV parsing has so many edge cases.
-
Tom Preston-Werner (2021). "TOML: Tom's Obvious Minimal Language" (Tier 1) https://toml.io/ TOML is a configuration file format that aims to be "a minimal configuration file format that's easy to read due to obvious semantics." Python 3.11+ includes
tomllibin the standard library. TOML is what JSON would be if it allowed comments and was designed for humans to write.
Character Encoding
- Spolsky, J. (2003). "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)" (Tier 1) https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/ A classic article that explains character encoding from first principles. If you've ever been confused by UTF-8, ASCII, Latin-1, or seen garbled characters in a file, this article will clarify everything. Over twenty years old and still essential reading.
Beyond Files: Databases
-
SQLite Home Page (Tier 1) https://www.sqlite.org/ SQLite is the most widely deployed database engine in the world (it's in every smartphone, every web browser, and many embedded systems). Python includes
sqlite3in the standard library. When your JSON or CSV files outgrow simple file I/O, SQLite is the natural next step. -
Sweigart, A. Automate the Boring Stuff with Python, Chapter 16: "Working with CSV Files and JSON Data" (Tier 1) Available free online. A practical, project-oriented take on CSV and JSON that complements this chapter with different examples and a focus on automation workflows.
For the Curious
-
The "Everything is a File" Philosophy (Tier 2) In Unix-based systems (Linux, macOS), virtually everything — disks, keyboards, network connections, even running processes — is represented as a file. This means the same
open/read/write/closepattern you learned in this chapter is the fundamental abstraction for all I/O in the operating system. Search for "Unix everything is a file" for articles exploring this design philosophy. -
Protocol Buffers and MessagePack (Tier 2) When JSON is too slow or too verbose, systems use binary serialization formats. Google's Protocol Buffers and MessagePack are two popular alternatives. You won't need them in this course, but if you're curious about how data is serialized at scale (millions of messages per second), they're worth investigating.