On Oct 15, 10:29 pm, Mark Harrison <m...@ohm.dynamic.pixar.com> wrote: > What's the magic to allow this? If the value is not specified I > would like to use the default value of 1. > > import optparse > p=optparse.OptionParser() > p.add_option("--debug") > > (opts, args) = p.parse_args(['--debug=22']); print opts > (opts, args) = p.parse_args(['--debug']); print opts
Unless you need to avoid third-party dependencies, install argparse (http://code.google.com/p/argparse) and don't give optparse another look. With argparse (which has a similar but not compatible api) you can do it like this: p=optparse.ArgumentParser() p.add_argument("--debug",nargs='?') Carl Banks -- http://mail.python.org/mailman/listinfo/python-list