Skip to content

bpo-38678: Improve argparse example in tutorial #17207

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 18, 2019

Conversation

rhettinger
Copy link
Contributor

@rhettinger rhettinger commented Nov 17, 2019

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an argparse beginner, I find the new example much more useful.

parser.add_argument('filenames', nargs='+')
parser.add_argument('-l', '--lines', type=int, default=10)
args = parser.parse_args()
print(args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a much better example for a beginner. With the prompts removed, and after switching from 'source diff' to 'rich diff', I could copy and paste the new code into an IDLE editor (and Run ... Customized to add sample args).

>>> parser.parse_args(['-vvv'])
Namespace(verbose=3)

Note, the *default* will be ``None`` unless explicitly set to *0*.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, not the tutorial, is the proper place to explain this.

@rhettinger rhettinger merged commit 04c79d6 into python:master Nov 18, 2019
@rhettinger rhettinger deleted the library_tour_argparse branch November 18, 2019 06:06
@miss-islington
Copy link
Contributor

Thanks @rhettinger for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 18, 2019
(cherry picked from commit 04c79d6)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
@bedevere-bot
Copy link

GH-17212 is a backport of this pull request to the 3.8 branch.

@bedevere-bot
Copy link

GH-17213 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 18, 2019
(cherry picked from commit 04c79d6)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
rhettinger added a commit that referenced this pull request Nov 18, 2019
(cherry picked from commit 04c79d6)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
rhettinger added a commit that referenced this pull request Nov 18, 2019
(cherry picked from commit 04c79d6)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
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
None yet
Development

Successfully merging this pull request may close these issues.

5 participants