Re: Re: [Python-Dev] anyone tried to use optparse with something else than sys.argv?

Erik Heneryd <[email protected]> Wed, 11 Dec 2002 17:17:22 +0100 (CET)
Newsgroups gmane.comp.python.optik.user
Message-ID <Pine.LNX.4.44.0212111641530.23201-100000@brain.secret.pythonware.com>
On Wed, 11 Dec 2002, Greg Ward wrote:

> On 10 December 2002, Erik Heneryd said:
> > well, i've tried to apply all those things in a patch (attached):
> > can't say i fully understand optparse, it's quite complex, so i thought 
> > i'd post it here for comments before anything else...
> 
> First bit of bad news: the optparse.py in Python's library is
> automatically generated from the Optik source, so patching optparse.py
> is a waste of time.  You'll need to get the Optik CVS tree from
> optik.sourceforge.net and hack on that.
> 

ah, i see.  you're going to keep the optik project cvs as the primary 
source and now and then sync to python?  however, i don't think it matter 
that i patched the wrong source, as the patch was meant to be more of a
this-is-what-i-mean-in-code thing.

> > the main thing i've done is that i've centralized the error handling.  if 
> > something goes wrong, error() is not called, but an exception raised.  all 
> > exceptions are then caught in parse_args().  there one can decide what to 
> > do with them - call error() or really throw an exception?
> 
> Sounds reasonable on the surface, but I'll need to look at your patch in
> detail before making up my mind.
> 
> > the help and version actions no longer call methods, they too raise 
> > exceptions, to be caught in parse_args().
> 
> That I'm not so sure about.  Hmmm.
> 
> I'm going to have to sit down with the list of problems you posted to
> python-dev and come up with my own solutions.  *Then* I'll understand
> your solutions.  We'll probably agree on some points and not on others
> -- that's life.

well, to summarize: what i've really been trying to address is the fact 
that optparse has some nasty side effects per default.  if you're out 
just to parse an argument list, and nothing more, you probably don't want 
that.

however, i guess that, in most cases you want to do initial sys.argv 
parsing, and then the default behaviour is fine.  lets keep it, it will 
save a couple of identical, extra lines in god knows how many programs.  
but, in all other cases, you want some easy way to turn those features off 
(printing and exiting).

if an exception raising mode is the best way to solve this i don't 
know, but i gave it a try anyway... :)


        erik, now on optik-users@



-------------------------------------------------------
This sf.net email is sponsored by:
With Great Power, Comes Great Responsibility 
Learn to use your power at OSDN's High Performance Computing Channel
http://hpc.devchannel.org/