Skip to content

bpo-37726: prefer argparse over getopt#15052

Merged
gvanrossum merged 4 commits into
python:masterfrom
mental32:bpo-37726-tutorial-getopt-argparse
Aug 1, 2019
Merged

bpo-37726: prefer argparse over getopt#15052
gvanrossum merged 4 commits into
python:masterfrom
mental32:bpo-37726-tutorial-getopt-argparse

Conversation

@mental32

@mental32 mental32 commented Jul 31, 2019

Copy link
Copy Markdown
Contributor

bpo-37726: prefer argparse over getopt in tutorial

The tutorial section on "command line arguments" recommended using getopt for argument parsing and referenced argparse as the fancy alternative.

The topic was raised in the python-ideas by Andrew and Guido created the issue and tagged it with the new "newcomer friendly" tag.

This is my first doc change so I'd greatly appreciate a review and especially criticism, if I did something wrong point it out so I can avoid repeating it.

https://bugs.python.org/issue37726

Comment thread Doc/tutorial/stdlib.rst Outdated
The :mod:`getopt` module processes *sys.argv* using the conventions of the Unix
:func:`getopt` function. More powerful and flexible command line processing is
provided by the :mod:`argparse` module.
The :mod:`argparse` module provides a mechanism to process command line arguments,

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.

I think sentence should end with .

@gvanrossum gvanrossum 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.

Thanks! I fixed the punctuation and otherwise I'm happy with this. I'll wait 24 hours for other core devs to jump in; if there's no more feedback I'll merge it.

@ericvsmith ericvsmith 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.

Thanks for your contribution!
See my comments about keeping with the same style as the rest of the document.

Comment thread Doc/tutorial/stdlib.rst Outdated

The three lines of code needed for creating the command line argument formula
are simple to read and understand and are easy to extend in terms of your
applications functionality.

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.

I think you should just let the example stand, instead of asserting that it's simple to read and extend.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was attempting to make obvious my point, but if the examples can stand on their own and have the same effect then I'll gladly omit the statement 👍

Comment thread Doc/tutorial/stdlib.rst Outdated

>>> parser.add_argument('--verbose', '-v', action='count')
>>> greeting = ["Hi", "Hello", "Greetings! its very nice to meet you"][args.verbose % 3]
>>> print(f'{greeting}, {args.name}')

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.

I think you should just include all of these examples in with the first example, and only have a single example, without any additional text. That seems to be how it's done in the rest of the document.

@gvanrossum

Copy link
Copy Markdown
Member

@mental32 Do you have time to make the changes suggested by Eric? The seem a good idea to me.

@mental32

mental32 commented Aug 1, 2019

Copy link
Copy Markdown
Contributor Author

@gvanrossum Indeed I do, changes will be pushed in the next twenty minutes :)

@matrixise matrixise 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.

Thank you for your contribution, I think we can merge this PR.

@gvanrossum
gvanrossum merged commit 2491134 into python:master Aug 1, 2019
@bedevere-bot

Copy link
Copy Markdown

@gvanrossum: Please replace # with GH- in the commit message next time. Thanks!

@gvanrossum

Copy link
Copy Markdown
Member

Thank you @mental32. Your contributions makes a difference!

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @mental32 for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @mental32 for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@bedevere-bot

Copy link
Copy Markdown

GH-15069 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 Aug 1, 2019
…5052)

(cherry picked from commit 2491134)

Co-authored-by: mental <m3nta1@yahoo.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 1, 2019
…5052)

(cherry picked from commit 2491134)

Co-authored-by: mental <m3nta1@yahoo.com>
@bedevere-bot

Copy link
Copy Markdown

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

gvanrossum pushed a commit that referenced this pull request Aug 1, 2019
…15070)

(cherry picked from commit 2491134)

Co-authored-by: mental <m3nta1@yahoo.com>
gvanrossum pushed a commit that referenced this pull request Aug 1, 2019
…15069)

(cherry picked from commit 2491134)

Co-authored-by: mental <m3nta1@yahoo.com>
@mental32
mental32 deleted the bpo-37726-tutorial-getopt-argparse branch August 1, 2019 21:19
lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request Jul 20, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants