tags:

views:

40

answers:

1

From Python docs:

"Option.dest : If the option’s action implies writing or modifying a value somewhere, this tells optparse where to write it: dest names an attribute of the options object that optparse builds as it parses the command line."

Can we put some check on the name of the attribute (dest) to check if it's value was provided? Say, I want to perform some action to determine it's value when no value is provided for it in CLI, as I don't have a fixed default value.

Checking against 'None' does not work.

A: 

You could use a default value of None for such options, which cannot be entered on the command line. Then you can check like

if opts.optional_value is None:
    # action for option not given
else:
    # use value from command line
Ber