python - Adding options which both change behaviour and store an argument -


Using the

argparse module, is it possible for many arguments to work?

Specifically, I use the -l / - list option nargs = '?' Change the behavior of the program from one of its main tasks to giving information about all possibilities or a particular possibility in the set.

Usually there will be a name space feature that has a function called parsing after; I need the -l option to change this attribute and alternatively store its logic in a different attribute.

Is this possible?

Just apply your own verb subclass this is basically like this Looks:

  class list action (argparse.Action): def __call __ (parser, namespace, value, option_string = none): setattr (namespace, 'list', value [0] ) Do_something_completely_different ()  

contains more details.


Comments