getopt: where's da dicts?????
Thomas A. Bryan
tbryan at python.net
Mon Oct 18 21:40:13 EDT 1999
Les Schaffer wrote:
>
> just started using the getopt module. i was surprised to see it
> returns the options in list format rather than perl's (better)
> dictionary format.
>
> i thought i read on c.l.p many moons ago about someone who had written
> an add-on to getopt to return a dict of options a la perl. but i found
> nothing in deja news for this.
Perhaps you're thinking of DPyGetOpt.
It provides features similar to those of Perl's
GetOpt::Long. I really wish that something like
this were in the standard Python library. I have
no idea what it would take to get such a module
added, but it's something that I *often* miss.
http://www.python.org/ftp/python/contrib/System/DPyGetOpt.py
It's pretty easy to use:
from DPyGetOpt import DPyGetOpt
import sys
optObject = DPyGetOpt(['foo|bar=s','baz','tim:i','peters'])
optObject.processArguments(sys.argv)
# Now, optObject.optionValues is a dict of option->value
# optObject.freeValues is the portion of argv unprocessed
# and optObject even has methods for querying the
# option dictionary
is-it-too-late-to-make-the-python-1.5.3-release?-ly yours
---Tom
P.S. I'm even willing to help recode an options module
such as DPyGetOpt according to whatever specs are necessary
to get it into the library.
More information about the Python-list
mailing list