Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue14034] Add argparse howto

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Mar 18, 2012, 3:06 PM

Post #1 of 16 (182 views)
Permalink
[issue14034] Add argparse howto

Tshepang Lekhonkhobe <tshepang [at] gmail> added the comment:

friendly ping

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Mar 18, 2012, 3:07 PM

Post #2 of 16 (176 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Éric Araujo <merwok [at] netwok> added the comment:

I’m going to Rietveld to review the patch.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Mar 18, 2012, 8:30 PM

Post #3 of 16 (175 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Éric Araujo <merwok [at] netwok> added the comment:

Sorry, a burger party fell on me. I’ll make time this week.

Nick, I just read on python-dev that you had suggestions for argparse docs; could you post the bug numbers / message IDs here or the list of suggestions?

----------
nosy: +ncoghlan

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Mar 18, 2012, 8:57 PM

Post #4 of 16 (174 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Nick Coghlan <ncoghlan [at] gmail> added the comment:

13850 (already mentioned above) is my relevant argparse docs proposal - it turns out the other argparse issues I remembered posting were actual feature requests rather than docs suggestions (FWIW, those are 14037 and 14039)

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Mar 18, 2012, 9:17 PM

Post #5 of 16 (174 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Nick Coghlan <ncoghlan [at] gmail> added the comment:

A couple of thoughts on the draft HOWTO:

I like the "verbosity" example, but I'd also like to see it continue on into introducing the "action='count'" alternative that allows "-vv" to set the verbosity level to 2, etc.

I also find the idea of having higher verbosity levels that aren't supersets of lower verbosity levels to be an anti-pattern, so I'd prefer not to see it in an official HOWTO. To my mind, verbosity levels should be checked with ">=", never "==".

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Mar 19, 2012, 1:34 AM

Post #6 of 16 (177 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Tshepang Lekhonkhobe <tshepang [at] gmail> added the comment:

> Nick Coghlan <ncoghlan [at] gmail> added the comment:
>
> A couple of thoughts on the draft HOWTO:
>
> I like the "verbosity" example, but I'd also like to see it continue on into introducing the "action='count'" alternative that allows "-vv" to set the verbosity level to 2, etc.

I wonder if this usage is common enough to get an entry in this
introductory text.

> I also find the idea of having higher verbosity levels that aren't supersets of lower verbosity levels to be an anti-pattern, so I'd prefer not to see it in an official HOWTO. To my mind, verbosity levels should be checked with ">=", never "==".

I don't really understand this paragraph. Do you have an example to
compare with any of the examples in the attached patch?

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Mar 19, 2012, 1:49 AM

Post #7 of 16 (174 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Tshepang Lekhonkhobe <tshepang [at] gmail> added the comment:

On Mon, Mar 19, 2012 at 10:34, Tshepang Lekhonkhobe <tshepang [at] gmail> wrote:
>> Nick Coghlan <ncoghlan [at] gmail> added the comment:
>>
>> A couple of thoughts on the draft HOWTO:
>>
>> I like the "verbosity" example, but I'd also like to see it continue on into introducing the "action='count'" alternative that allows "-vv" to set the verbosity level to 2, etc.
>
> I wonder if this usage is common enough to get an entry in this
> introductory text.
>
>> I also find the idea of having higher verbosity levels that aren't supersets of lower verbosity levels to be an anti-pattern, so I'd prefer not to see it in an official HOWTO. To my mind, verbosity levels should be checked with ">=", never "==".
>
> I don't really understand this paragraph. Do you have an example to
> compare with any of the examples in the attached patch?

After playing a bit more with this and thinking about it a bit, I do
get your point. It makes a lot of sense. I will attach a patch soon,
which will also include the count keyword. Thanks for the review.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Mar 19, 2012, 3:50 AM

Post #8 of 16 (174 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Tshepang Lekhonkhobe <tshepang [at] gmail> added the comment:

> After playing a bit more with this and thinking about it a bit, I do
> get your point. It makes a lot of sense. I will attach a patch soon,
> which will also include the count keyword. Thanks for the review.

Find attached. Note that I kept some of those anti-pattern examples
you mentioned, and then later on introduced your preferred way of
doing things (using action="count" and ">=" checks instead of "=="
ones).

----------
Added file: http://bugs.python.org/file24937/argparse_howto2.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
Attachments: argparse_howto2.patch (25.4 KB)


report at bugs

Mar 19, 2012, 4:02 AM

Post #9 of 16 (176 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Tshepang Lekhonkhobe <tshepang [at] gmail> added the comment:

> Find attached. Note that I kept some of those anti-pattern examples
> you mentioned, and then later on introduced your preferred way of
> doing things (using action="count" and ">=" checks instead of "=="
> ones).

Reason I kept those is to easily lead the reader into the "more
correct" way of doing things, by first doing them in a more obvious
but less ideal way.

For example, when the goal of one is to teach one to remove duplicates
from list, it's nice if you first do the process manually, and then
later on introduce the set() type, just so the user can appreciate
them more. Same applies to doing "for item in range(len(iterable))"
vs. "for item in iterable".

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Mar 19, 2012, 4:11 AM

Post #10 of 16 (175 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Tshepang Lekhonkhobe <tshepang [at] gmail> added the comment:

Okay, there was some bad markup on my version 2. Lemme fix.

----------
Added file: http://bugs.python.org/file24938/argparse_howto2.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Mar 19, 2012, 5:20 AM

Post #11 of 16 (174 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Changes by Tshepang Lekhonkhobe <tshepang [at] gmail>:


Removed file: http://bugs.python.org/file24937/argparse_howto2.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Mar 19, 2012, 6:05 AM

Post #12 of 16 (173 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Nick Coghlan <ncoghlan [at] gmail> added the comment:

Rather than "is recommended by at least one core CPython developer" I'd say "matches the way the CPython executable handles its own verbosity argument" (check the output of "python --help")

Also, a better fix for the non-orderable types problem is to use "default=0" when defining the verbosity arg rather than changing the test in the code.

Finally, the "not a superset" problem that I have with the way the running example uses its verbosity argument is that it uses it to *change* the message that gets displayed, instead of using it to *display more messages* at higher verbosity levels.

>From that point of view, more idiomatic usage might look something like:

if verbosity >= 2:
print("Running {!r}".format(self.__file__)
if verbosity >= 1:
print("Calculating {}^2".format(args.square)
print(answer)

However, I'll grant that things like test runners do use their verbosity argument to switch from shorthand progress markers to printing out the test names and results, so I can live with the examples as they are.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Mar 19, 2012, 7:42 AM

Post #13 of 16 (173 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Tshepang Lekhonkhobe <tshepang [at] gmail> added the comment:

> Nick Coghlan <ncoghlan [at] gmail> added the comment:
>
> Rather than "is recommended by at least one core CPython developer" I'd say "matches the way the CPython executable handles its own verbosity argument" (check the output of "python --help")

Done.

> Also, a better fix for the non-orderable types problem is to use "default=0" when defining the verbosity arg rather than changing the test in the code.

Done.

> Finally, the "not a superset" problem that I have with the way the running example uses its verbosity argument is that it uses it to *change* the message that gets displayed, instead of using it to *display more messages* at higher verbosity levels.
>
> >From that point of view, more idiomatic usage might look something like:
>
>    if verbosity >= 2:
>        print("Running {!r}".format(self.__file__)
>    if verbosity >= 1:
>        print("Calculating {}^2".format(args.square)
>    print(answer)

Yeah, I clearly didn't understand what you meant by 'superset'. I've
added one example similar to the above.

These were good suggestions. I've attached the patch.

----------
Added file: http://bugs.python.org/file24941/argparse_howto3.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
Attachments: argparse_howto3.patch (26.7 KB)


report at bugs

Mar 19, 2012, 7:48 AM

Post #14 of 16 (176 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Tshepang Lekhonkhobe <tshepang [at] gmail> added the comment:

Fixing a markup error. Sorry for the noise.

----------
Added file: http://bugs.python.org/file24942/argparse_howto3.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
Attachments: argparse_howto3.patch (26.7 KB)


report at bugs

Mar 19, 2012, 7:49 AM

Post #15 of 16 (175 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Changes by Tshepang Lekhonkhobe <tshepang [at] gmail>:


Removed file: http://bugs.python.org/file24941/argparse_howto3.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Mar 31, 2012, 4:43 AM

Post #16 of 16 (157 views)
Permalink
[issue14034] Add argparse howto [In reply to]

Tshepang Lekhonkhobe <tshepang [at] gmail> added the comment:

Would be nice to get another review.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue14034>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.