Skip to content

bpo-38678: Improve argparse example in tutorial#17207

Merged
rhettinger merged 3 commits into
python:masterfrom
rhettinger:library_tour_argparse
Nov 18, 2019
Merged

bpo-38678: Improve argparse example in tutorial#17207
rhettinger merged 3 commits into
python:masterfrom
rhettinger:library_tour_argparse

Conversation

@rhettinger

@rhettinger rhettinger commented Nov 17, 2019

Copy link
Copy Markdown
Contributor

@terryjreedy terryjreedy left a comment

Copy link
Copy Markdown
Member

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.

Comment thread Doc/tutorial/stdlib.rst
parser.add_argument('filenames', nargs='+')
parser.add_argument('-l', '--lines', type=int, default=10)
args = parser.parse_args()
print(args)

Copy link
Copy Markdown
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).

Comment thread Doc/library/argparse.rst
>>> parser.parse_args(['-vvv'])
Namespace(verbose=3)

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

@bedevere-bot

Copy link
Copy Markdown

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