Skip to content

Conversation

@Vemulakonda559
Copy link

@Vemulakonda559 Vemulakonda559 commented Nov 29, 2025

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 issue python#141395
Removed duplicate text and improved clarity in the note about stdout flushing behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants