Skip to content

gh-162868: Fix the collections.namedtuple examples - #162869

Merged
StanFromIreland merged 2 commits into
python:mainfrom
XinYuDu-AI:patch-1
Nov 30, 2026
Merged

StanFromIreland merged 2 commits into
python:mainfrom
XinYuDu-AI:patch-1

Conversation

@XinYuDu-AI

@XinYuDu-AI XinYuDu-AI commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #162868.

I noticed that the EmployeeRecord example in the Python 3.15 docs still opens employees.csv in binary mode. The Python 2.6 example used "rb", and the Python 3.0 version updated the print statement but kept the file mode.

Open the file as UTF-8 text so csv.reader receives strings. Use newline="" to let the reader handle line endings and a with block to close the file after iteration.

I used Codex to help work out and test the fix and draft this description. On CPython 3.15.2, the original loop raised csv.Error on the first row. The corrected loop printed Alice Engineer for the same input and preserved an embedded CRLF in a separate test with a quoted field.

Refactor file handling for employee records to use a context manager.
@python-cla-bot

python-cla-bot Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@StanFromIreland StanFromIreland changed the title gh-162868: Fix the CSV file mode in the collections.namedtuple example gh-162868: Fix the collections.namedtuple examples Nov 30, 2026
@StanFromIreland StanFromIreland added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 30, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #36273172 | 📁 Comparing 2b1b5db against main (9d6fa5d)

  🔍 Preview build  

1 file changed
± library/collections.html

@StanFromIreland
StanFromIreland merged commit 114f465 into python:main Nov 30, 2026
39 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Nov 30, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @XinYuDu-AI for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 30, 2026

Copy link
Copy Markdown

GH-162884 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 30, 2026
@bedevere-app

bedevere-app Bot commented Nov 30, 2026

Copy link
Copy Markdown

GH-162885 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 30, 2026
StanFromIreland added a commit that referenced this pull request Nov 30, 2026
… (#162884)

(cherry picked from commit 114f465)

Co-authored-by: XinYuDu-AI <112471882+XinYuDu-AI@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
StanFromIreland added a commit that referenced this pull request Nov 30, 2026
… (#162885)

(cherry picked from commit 114f465)

Co-authored-by: XinYuDu-AI <112471882+XinYuDu-AI@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

The collections.namedtuple example opens a CSV file in binary mode

3 participants