
parse_args () Namespace(foo=None, one='X') > # negative number options present, so -2 is an option > parser. add_argument ( 'foo', nargs = '?' ) > # negative number options present, so -1 is an option > parser. add_argument ( '-1', dest = 'one' ) > parser. ArgumentParser ( prog = 'PROG' ) > parser. parse_args () Namespace(foo='-5', x='-1') > parser = argparse. parse_args () Namespace(foo=None, x='-1') > # no negative number options, so -1 and -5 are positional arguments > parser. add_argument ( 'foo', nargs = '?' ) > # no negative number options, so -1 is a positional argument > parser. The _call_ method may perform arbitrary actions, but will typically setĪttributes on the namespace based on dest and values. Is associated with a positional argument. The option_string argument is optional, and will be absent if the action

#Argparse python 3 install plus
Plus any keyword arguments passed to ArgumentParser.add_argument() The Action class must accept the two positional arguments Needed to parse a single argument from one or more strings from theĬommand line. Action ( option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None )Īction objects are used by an ArgumentParser to represent the information This API may be passed as the action parameter toĪdd_argument(). Which processes arguments from the command-line. The following sections describe how each of these are used.Īction classes implement the Action API, a callable which returns a callable dest - The name of the attribute to be added to the object returned by.metavar - A name for the argument in usage messages.help - A brief description of what the argument does.


argument_default - The global default value for arguments.Which additional arguments should be read (default: None) fromfile_prefix_chars - The set of characters that prefix files from.prefix_chars - The set of characters that prefix optional arguments.formatter_class - A class for customizing the help output.parents - A list of ArgumentParser objects whose arguments should.epilog - Text to display after the argument help (default: none).description - Text to display before the argument help (default: none).usage - The string describing the program usage (default: generated from.prog - The name of the program (default: sys.argv).

Each parameter has its own more detailed description All parameters should be passedĪs keyword arguments. ArgumentParser ( prog=None, usage=None, description=None, epilog=None, parents=, formatter_class=argparse.HelpFormatter, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True )Ĭreate a new ArgumentParser object.
