Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-141395: Clarify stdout flush behavior for newline characters in print()#142094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Vemulakonda559 wants to merge12 commits intopython:main
base:main
Choose a base branch
Loading
fromVemulakonda559:Vemulakonda559-patch-1

Conversation

@Vemulakonda559
Copy link

@Vemulakonda559Vemulakonda559 commentedNov 29, 2025
edited by github-actionsbot
Loading

This PR adds a note to the print() documentation to clarify how Python’s stdout buffering works with newline (\n) characters inside a single print call.

Motivation:

Current documentation mentions that flush() is implied for writes containing newlines.

However, it does not explain that Python flushes only after the entire write operation, not mid-string.

This can confuse users coming from C, who expect a flush at each newline, and developers writing scripts that rely on immediate output for progress indicators or CLI feedback.

What’s added:

A .. note:: block explaining that stdout behavior depends on the environment (TTY vs redirected stdout).

Guidance on explicitly flushing with flush=True or sys.stdout.flush().

Mention of python -u for unbuffered output.

A short example demonstrating the behavior.

Impact:

Improves clarity for learners and developers.

Aligns documentation with actual behavior across different environments.

Not a behavior change — documentation-only PR.

Related Issue:

Addresses issue#141395


📚 Documentation preview 📚:https://cpython-previews--142094.org.readthedocs.build/

This PR adds a note to the print() documentation to clarify how Python’s stdout buffering works with newline (\n) characters inside a single print call.Motivation:Current documentation mentions that flush() is implied for writes containing newlines.However, it does not explain that Python flushes only after the entire write operation, not mid-string.This can confuse users coming from C, who expect a flush at each newline, and developers writing scripts that rely on immediate output for progress indicators or CLI feedback.What’s added:A .. note:: block explaining that stdout behavior depends on the environment (TTY vs redirected stdout).Guidance on explicitly flushing with flush=True or sys.stdout.flush().Mention of python -u for unbuffered output.A short example demonstrating the behavior.Impact:Improves clarity for learners and developers.Aligns documentation with actual behavior across different environments.Not a behavior change — documentation-only PR.Related Issue:Addresses issuepython#141395
Removed duplicate text and improved clarity in the note about stdout flushing behavior.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

Assignees

No one assigned

Labels

awaiting reviewdocsDocumentation in the Doc dirskip news

Projects

Status: Todo

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@Vemulakonda559@StanFromIreland

[8]ページ先頭

©2009-2025 Movatter.jp