You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The collections.namedtuple example opens a CSV file in binary mode #162868
While reading the Python 3.15 documentation for collections.namedtuple, I noticed that the EmployeeRecord example opens employees.csv in binary mode and passes it to csv.reader. On Python 3, iterating over that file yields bytes, but csv.reader expects strings.
This line dates back to the Python 2.6 example. The Python 3.0 version updated the print statement but kept "rb", which is still present in the Python 3.15 docs.
Reproduction
Save the following row in employees.csv:
Alice,30,Engineer,Engineering,5
From the same directory, run the CSV portion of the documented example, with namedtuple imported:
After spotting the issue, I used Codex to help work out the fix and test both versions locally on CPython 3.15.2. The corrected loop printed Alice Engineer for the same input.
Activity
gh-162868: Fix the `collections.namedtuple` examples (#162869)
[3.15] gh-162868: Fix the `collections.namedtuple` examples (GH-162869)…
[3.14] gh-162868: Fix the `collections.namedtuple` examples (GH-162869)…