getopt

John Machin sjmachin at lexicon.net
Wed Feb 11 01:36:40 EST 2009


On Feb 11, 4:36 pm, Matthew Sacks <ntw... at gmail.com> wrote:
> The documentation leaves lack for want, especially the examples.

You had two problems:

(1) str(passedArgs): The docs make it plain that "args" is a list, not
a str instance: """args is the argument list to be parsed, without the
leading reference to the running program. Typically, this means
sys.argv[1:]""". The 1st and 2nd examples spell out the same story;
here's the 2nd:
"""
 Using long option names is equally easy:
 >>> s = '--condition=foo --testing --output-file abc.def -x a1 a2'
 >>> args = s.split()
 >>> args
 ['--condition=foo', '--testing', '--output-file', 'abc.def', '-x',
'a1', 'a2']
"""

(2) omitting the *required* options arg: (a) it's not wrapped in [] so
it's required (b) the docs say """To accept only long options, options
should be an empty string."""

IOW, it may "leave lack for want", but not in the areas causing you a
bother.



More information about the Python-list mailing list