Skip to content

Add materials for Reading and Writing CSV Files in Python - #841

Open
realpython-bot wants to merge 1 commit into
masterfrom
materials/python-csv-20260916
Open

realpython-bot wants to merge 1 commit into
masterfrom
materials/python-csv-20260916

Conversation

@realpython-bot

Copy link
Copy Markdown
Collaborator

This is a NEW folder for a tutorial that has never had companion code, so it needs an editorial eye as well as a code review — there is no previous version of python-csv/ to diff against.

Source of truth: the updated draft, not the live article.

What the folder contains

Six scripts, one per code-bearing section of the tutorial, in article order:

File Tutorial section
read_csv_with_reader.py Reading CSV Files With csv
read_csv_into_dictionary.py Reading CSV Files Into a Dictionary With csv
write_csv_with_writer.py Writing CSV Files With csv
write_csv_from_dictionary.py Writing CSV File From a Dictionary With csv
read_csv_with_pandas.py Reading CSV Files With pandas
write_csv_with_pandas.py Writing CSV Files With pandas

Plus the three data files the article shows — employee_birthday.csv, employee_addresses.csv, hrdata.csv — a README.md, and a requirements.txt pinned to the draft's dependencies field (pandas==3.0.5; the draft also pins python==3.14, which isn't a pip requirement).

The files the tutorial generates (employee_file.csv, employee_file2.csv, hrdata_modified.csv) are deliberately not checked in — running the writing scripts produces them. The README says so.

REPL examples were turned into runnable scripts

The tutorial's two pycon blocks (the type() checks on df['Hire Date']) are not shipped as separate snippets. They're folded into read_csv_with_pandas.py as print() calls at exactly the point in the section where the article shows them, so the whole "Reading CSV Files With pandas" progression runs top to bottom as one coherent script with the article's own variable names and ordering. No examples were invented and no code was "improved" beyond the repo's formatter.

How it was verified

  • Built a venv on the article's own pin: Python 3.14.6, pandas==3.0.5.
  • Executed all six scripts and diffed their stdout against the console blocks in the draft. Every one matches, including <class 'str'>, <class 'pandas.Timestamp'>, and all four DataFrame renderings.
  • Checked the three generated CSVs against the file contents the article shows. All match.
  • Repo gates at the version the root requirements.txt pins: uvx ruff@0.14.1 format --check python-csv and uvx ruff@0.14.1 check python-csv both pass.
  • Nothing in this tutorial needs a server, a GUI, or a paid API key, so nothing was skipped.

Note for review: ruff format rewrote the article's single quotes to double quotes and wrapped a few long calls, so the shipped code is house-formatted rather than a character-for-character copy of the article's blocks. Logic, ordering, and variable names are unchanged.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant