Skip to content

Sync python-while-loop with the updated tutorial - #834

Open
realpython-bot wants to merge 1 commit into
masterfrom
maintenance/python-while-loop-20260916
Open

realpython-bot wants to merge 1 commit into
masterfrom
maintenance/python-while-loop-20260916

Conversation

@realpython-bot

Copy link
Copy Markdown
Collaborator

Brings python-while-loop/ back in line with the current state of Python while Loops: Repeating Tasks Conditionally, which has just been through a maintenance update.

What changed and why

for_loop.py — output drift (the reason this PR exists).
The script printed "\nWith a for-loop" / "\nWith a while-loop", but the tutorial's code block and its $ python for_loop.py console block both show the headings unhyphenated. This cycle's update corrected the console block to the unhyphenated text, so the shipped script was the last thing still printing hyphens. Now dehyphenated to match; the script's stdout is byte-for-byte identical to the console block in the article.

connection.py — value drift. time.sleep(0.5) -> time.sleep(0.3), matching the tutorial's code block.

break.py, continue.py, guess.py — missing files. The tutorial presents all three as named, downloadable scripts (```python filename="break.py" etc., plus $ python break.py / $ python continue.py console blocks), but they were never added to this folder. Added verbatim from the article's code blocks. Their output matches the tutorial's console blocks exactly.

Not changed, deliberately

  • Blank-line differences. Several files differ from the article's code blocks only in blank-line count (temperature.py, password.py, user_input.py, and the second gap in for_loop.py). These are CMS display compression, not drift — applying temperature.py's article spacing verbatim would put one blank line around a top-level def and fail ruff format --check. The repo's PEP 8 spacing is kept.
  • user_input.py keeps the trailing walrus-operator loop. The tutorial shows that variant as a pycon block rather than a named file, which is the same convention already used for infinite.py and remove.py in this folder.
  • No requirements.txt. The tutorial's dependencies field is python==3.14 with no third-party packages, and every script here is stdlib-only (random, time, pathlib). There is nothing for a reader to install, so no requirements file is added.
  • api_calls.py, logfile.py, process_pairs.py are left in place. They no longer correspond to anything in the current article text, but they've been part of this folder since it was created and removing reader-facing files is an editorial call rather than a sync fix. Flagging for a human.

How this was verified

  • Fresh venv on the article's new pin, CPython 3.14.6 (the python==3.13 -> python==3.14 bump is part of this update cycle).
  • Every one of the 15 scripts executed to a clean exit, not just resolved — MPLBACKEND=Agg set. The interactive ones (user_input.py, password.py on both the success and lockout paths, guess.py) were driven with piped stdin; check_file.py and logfile.py were driven by a background writer creating hello.txt / appending to file.log; temperature.py and api_calls.py ran to natural termination.
  • Output of break.py, continue.py, and for_loop.py diffed against the corresponding console blocks in the tutorial — exact match.
  • Repo gates on the version this repo's requirements.txt pins, ruff==0.14.1: ruff format --check python-while-loop -> 14 files already formatted; ruff check python-while-loop -> All checks passed!.

Needs a human merge.

🤖 Generated with Claude Code

…ops: Repeating Tasks Conditionally

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant