What should Python apps do when asked to show help?

Dan Strohl D.Strohl at F5.com
Thu Apr 28 13:39:57 EDT 2016


Yup.. another reason to use something like argparse... you define the argument descriptions, help, and when you raise an error, it automatically handles the output, sending it to the right place (stderr/stdout)... as well as allowing you to define different levels of verbosity easily... (or not if you don't want)

Argparse isn't the best tool in the world, and there are some things that annoy me about it sometimes, but it works pretty well within its boundaries.

(and if the code's already written, I'm not suggesting that it be re-written just to move it to a common library.

> -----Original Message-----
> From: Python-list [mailto:python-list-bounces+d.strohl=f5.com at python.org]
> On Behalf Of Random832
> Sent: Thursday, April 28, 2016 10:30 AM
> To: python-list at python.org
> Subject: Re: What should Python apps do when asked to show help?
> 
> On Thu, Apr 28, 2016, at 13:06, Chris Angelico wrote:
> > On Fri, Apr 29, 2016 at 2:33 AM, Steven D'Aprano <steve at pearwood.info>
> > wrote:
> > > Many command line tools simply output help to stdout (or stderr, if
> > > they're evil),
> >
> > I'm not sure stderr is particularly more evil than stdout, but
> > whatever
> > :)
> 
> When a tool has very long help and sends it to stderr:
> 
> $ foo --help
> ok, it's scrolled off the top, and I could just scroll up, but it's so long I'll have to
> search for what I want anyway.
> $ foo --help | less
> *help flashes on the screen, then blank ~~~~~~ screen from less*
> #@!@#$#$!#$!@#$@#!$@!#$!@#$!@#$!@#$!@#$
> $ foo --help 2>&1 | less
> 
> Basically the only reason this ever happens is that programmers get lazy and
> use the same function for usage errors as for --help. A usage error message
> *should* go to stderr (in order to show up if the program's output has been
> redirected to null, and so as not to be silently piped to something that
> expects the program's normal output), but it should be short. Help should go
> to stdout because the user actually requested it.
> 
> The obvious exception, and probably the bad example that people are
> following, is programs that don't actually *have* --help, but briefly
> summarize all their options and the meanings of positional arguments in the
> usage error. People start with that, and then expand it to a full-blown GNU-
> style --help message, but continue sending it to stderr.
> --
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list