Suggestion: UnixOptionParser class in optparse.py
Rich Harkins
rharkins at thinkronize.com
Mon Jan 6 11:35:18 EST 2003
I love the OptionParser class. Good stuff. The only thing that I would
want different (right now anyway) would be a simple way to parse Unix
style options (first non-option argument terminates options). My
proposal is to add a tiny subclass in optparse.py that would handle
this:
class UnixOptionParser(OptionParser):
"""
Parse options just like OptionParser except disallow
interspersed options by default.
"""
def __init__(self,*args,**kw):
OptionParser.__init__(self,*args,**kw)
self.allow_interspersed_args=0
This would provide the best of both worlds IMO. I can understand why
some users would like the interspersed args, but it makes it harder to
provide applications consistent with other Unix commands. I would have
to wrap this separately to provide wrapper programs. For example,
mydebugger [options] command args...
will fail if args contains any flags.
Anyway, that's my 2 cents for what it's worth.
Rich
More information about the Python-list
mailing list