Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Dan Strohl Newsgroups: comp.lang.python Subject: RE: What should Python apps do when asked to show help? Date: Thu, 28 Apr 2016 17:39:57 +0000 Lines: 61 Message-ID: References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461864606.3216317.592558881.0591528C@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de 5HJlNJ55LoMDUvbwJdHgVAxwUkNGe5h3/jgMoHgIe1Jg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.04; 'subject:Python': 0.05; 'null,': 0.07; 'redirected': 0.07; 'subject:help': 0.07; 'boundaries.': 0.09; 'exception,': 0.09; 'output,': 0.09; 'positional': 0.09; 'skip:# 30': 0.09; 'stderr': 0.09; 'stdout': 0.09; 'python': 0.10; 'output': 0.13; 'thursday,': 0.13; 'apps': 0.15; 'argument': 0.15; 'message-----': 0.15; 'thu,': 0.15; '*should*': 0.16; '--help': 0.16; '--help.': 0.16; '2016': 0.16; '2>&1': 0.16; 'argparse': 0.16; 'expects': 0.16; 'help?': 0.16; 're-written': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'screen,': 0.16; 'skip:[ 50': 0.16; 'stderr.': 0.16; 'stderr:': 0.16; 'subject:show': 0.16; 'subject:when': 0.16; 'summarize': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'written,': 0.18; '(in': 0.18; 'handles': 0.20; 'to:name:python-list@python.org': 0.20; 'to:2**1': 0.21; 'arguments': 0.22; 'sends': 0.22; 'am,': 0.23; '(or': 0.23; 'errors': 0.23; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'command': 0.26; 'chris': 0.26; 'error': 0.27; 'define': 0.27; 'fri,': 0.27; 'function': 0.28; 'received:192.168.10': 0.29; 'raise': 0.29; 'asked': 0.29; "i'm": 0.30; 'url:mailman': 0.30; 'programmers': 0.30; 'error.': 0.31; 'probably': 0.31; 'another': 0.32; 'screen': 0.32; 'help,': 0.32; 'options': 0.33; 'url:python': 0.33; 'common': 0.33; "d'aprano": 0.33; 'foo': 0.33; 'steven': 0.33; "i'll": 0.33; 'skip:- 10': 0.34; 'url:listinfo': 0.34; 'that,': 0.34; 'sent:': 0.35; 'world,': 0.35; 'could': 0.35; 'library.': 0.35; 'something': 0.35; 'subject:': 0.35; "isn't": 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'tool': 0.36; '(and': 0.36; 'email addr:python.org': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'things': 0.38; 'sure': 0.39; 'whatever': 0.39; 'from:': 0.39; 'received:192': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'some': 0.40; 'ever': 0.60; 'show': 0.62; 'programs': 0.62; 'more': 0.63; 'different': 0.63; 'within': 0.64; 'python-list': 0.66; "they're": 0.66; 'email name :python-list': 0.67; 'levels': 0.70; 'obvious': 0.76; 'flashes': 0.84; 'received:192.168.15': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=f5.com; i=@f5.com; q=dns/txt; s=seattle; t=1461865202; x=1493401202; h=from:to:subject:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version; bh=qehSv1InY3FGf1i8HDKglOkCyzAYl4NEEoioLNsXyTc=; b=hZ+WGHiFeXN/qMCaZeVbV/jgXRmTVt+Bl/9SKA/4UO+KOwg7pg9TTvAS sjFhowXaCXVLcmcTnVU96zD10F/mPmrHjFCIcCggFT4zcNolP/JK3SC+3 5AwQIU80Gbtk5XOIuaiwHPGp9GSDsBhG6u/+OyA/V9KJEuuS1r8KY+0dH o=; X-IronPort-AV: E=Sophos;i="5.24,547,1454976000"; d="scan'208";a="216227661" Thread-Topic: What should Python apps do when asked to show help? Thread-Index: AQHRoWw0yo/CeHHw+k+f9dhTV82UOp+gExQAgAAGoQD//4vT0A== In-Reply-To: <1461864606.3216317.592558881.0591528C@webmail.messagingengine.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [192.168.15.239] X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <57223b76$0$22140$c3e8da3$5496439d@news.astraweb.com> <1461864606.3216317.592558881.0591528C@webmail.messagingengine.com> Xref: csiph.com comp.lang.python:107818 Yup.. another reason to use something like argparse... you define the argum= ent descriptions, help, and when you raise an error, it automatically handl= es 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 y= ou don't want) Argparse isn't the best tool in the world, and there are some things that a= nnoy 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-writte= n just to move it to a common library. > -----Original Message----- > From: Python-list [mailto:python-list-bounces+d.strohl=3Df5.com@python.or= g] > On Behalf Of Random832 > Sent: Thursday, April 28, 2016 10:30 AM > To: python-list@python.org > Subject: Re: What should Python apps do when asked to show help? >=20 > On Thu, Apr 28, 2016, at 13:06, Chris Angelico wrote: > > On Fri, Apr 29, 2016 at 2:33 AM, Steven D'Aprano > > 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 > > :) >=20 > When a tool has very long help and sends it to stderr: >=20 > $ foo --help > ok, it's scrolled off the top, and I could just scroll up, but it's so lo= ng 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 >=20 > 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 messa= ge > *should* go to stderr (in order to show up if the program's output has be= en > 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. >=20 > 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 t= he > usage error. People start with that, and then expand it to a full-blown G= NU- > style --help message, but continue sending it to stderr. > -- > https://mail.python.org/mailman/listinfo/python-list