optparser question

Michele Petrazzo michele.petrazzoDELETE at DELETEunipex.it
Fri Dec 22 07:38:16 EST 2006


I'm trying optparse and I see a strange (for me) behavior:

def store_value(option, opt_str, value, parser):
     setattr(parser.values, option.dest, value)

parser = optparse.OptionParser()
parser.add_option("-f", "--foo",
                   action="callback", callback=store_value,
                   type="int", dest="foo")

args = ["-f", "1"]
(options, args) = parser.parse_args(args)
print options, args

{'foo': 1} [] # with the type
{'foo': None} ['1'] #without it

If I not specify the type in add_options, the value aren't passed to the
store_value (into value variable), but it's understood as args!
If I specify it, it

Is this normal?

Thanks,
Michele



More information about the Python-list mailing list