Commit 7cc4851
authored
Clarify stdout flush behavior for newline characters in print()
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 #1413951 parent 9ce99c6 commit 7cc4851
1 file changed
+25
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1607 | 1607 | | |
1608 | 1608 | | |
1609 | 1609 | | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
1610 | 1635 | | |
1611 | 1636 | | |
1612 | 1637 | | |
| |||
0 commit comments