getopt issues

Steven Taschuk staschuk at telusplanet.net
Wed Aug 27 17:18:33 EDT 2003


Quoth David Bear:
  [...]
> now that I've read a little more of the getopt documentation, it says that 
> getopt stops processing when a 'nonoption' is encounted.  Is there a way 
> to have it process the whole argument list, then only return the options 
> specified in options, rather than have it through an exception and return 
> nothing?

I don't think so.  This is an unusual request -- normally it is
desirable for a program to insist on correct usage, rather than
trying to guess what the user meant.  (Imagine, for example, that
a user types 'rm -I *', intending 'rm -i *', and rm just ignores
the unknown option '-I'.  This would be bad.)

It might, however, be possible to subclass optparse.OptionParser
to get the behaviour you want.  (The optparse module is new in the
2.3 stdlib.)

-- 
Steven Taschuk                  staschuk at telusplanet.net
"Telekinesis would be worth patenting."  -- James Gleick





More information about the Python-list mailing list