[Python-Dev] getopt helper?
Thu, 30 Sep 1999 17:28:31 +0200
Guido van Rossum wrote:
> > > > > Basically _every_ time I use getopt, I write code like this:
> > > > Why not just add a higher level interface ? Something
> > > > like CommandLine.py which is included in mxDateTime ?
> > > Because _every_ time I use getopt, I write code like that :-)
> > I wrote the CommandLine.py for pretty much the same reason:
> Marc-Andre, you're not hearing what Mark is saying. He wants a change
> to the standard library, and he knows that small additions to existing
> modules there stand a better chance of adoption than new modules.
Oh, I did get the idea... just wanted to plug my module here in a
take-it-or-leave-it way ;-) I usually put such things into
my lib/ dir for Python to find -- no need to make them a standard.
> I personally liked the idea of getoptex() best, except I would call it
> getopt_or_die(). If the usage message is omitted it can synthesize
> one from the (short and long) options arguments and sys.argv (the
> latter being a bit controversial, but it's just a default).
> Hmm... Perhaps getopt_or_die() shouldn't take the args argument but
> extract sys.argv[1:] itself?
Better not: it's sometimes very useful to call the main(args) function
of a script in interactive mode which then passes the args list to
getopt(). How about adding something like:
def getoptex(...,args=None,helptext='Read the source, Luke ;-)'):
if args is None: args = sys.argv[1:]
Y2000: 92 days left
Python Pages: http://www.lemburg.com/python/