Thursday, November 21, 2013

[Python2] Everything you want to know about argparse standard lib

To see all kwargs that you can pass to ArgumentParser.add_argument(), run python/ipython and type:

>>> import argparse
>>> help(argparse.Action)

Regarding to action kwarg, below is all action that you can pass:
        # register actions
        self.register('action', None, _StoreAction)
        self.register('action', 'store', _StoreAction)
        self.register('action', 'store_const', _StoreConstAction)
        self.register('action', 'store_true', _StoreTrueAction)
        self.register('action', 'store_false', _StoreFalseAction)
        self.register('action', 'append', _AppendAction)
        self.register('action', 'append_const', _AppendConstAction)
        self.register('action', 'count', _CountAction)
        self.register('action', 'help', _HelpAction)
        self.register('action', 'version', _VersionAction)
        self.register('action', 'parsers', _SubParsersAction)
Example:
parser.add_argument("-v", "--verbose", action="store_true",
                    help="increase output verbosity")
 
More example 
http://docs.python.org/2.7/howto/argparse.html 

2 comments:

7kai said...

http://stackoverflow.com/questions/810409/haskell-or-standard-ml-for-beginners

7kai said...

http://stackoverflow.com/questions/810409/haskell-or-standard-ml-for-beginners