All of the above examples involve setting some variable (the
``destination'') when certain command-line options are seen. What
happens if those options are never seen? Since we didn't supply any
defaults, they are all set to None. Sometimes, this is just fine (which
is why it's the default), but sometimes, you want more control. To
address that need, optparse lets you supply a default value for
each destination, which is assigned before the command-line is parsed.
First, consider the verbose/quiet example. If we want
optparse to set verbose to True unless
-q is seen, then we can do this:
Those are equivalent because you're supplying a default value for the
option's destination, and these two options happen to have the same
destination (the verbose variable).