M
Michele Petrazzo
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
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