argparse.ArgumentParser

简介:
实例化一个对象,默认参数一堆,只有description参数可以设置一下
parser=argparse.ArgumentParser( description="This is a example program ")
add_help:默认是True,可以设置False禁用



class ArgumentParser(_AttributeHolder, _ActionsContainer)
 |  Object for parsing command line strings into Python objects.
 |  
 |  Keyword Arguments:
 |      - prog -- The name of the program (default: sys.argv[0])
 |      - usage -- A usage message (default: auto-generated from arguments)
 |      - description -- A description of what the program does
 |      - epilog -- Text following the argument descriptions
 |      - parents -- Parsers whose arguments should be copied into this one
 |      - formatter_class -- HelpFormatter class for printing help messages
 |      - prefix_chars -- Characters that prefix optional arguments
 |      - fromfile_prefix_chars -- Characters that prefix files containing
 |          additional arguments
 |      - argument_default -- The default value for all arguments
 |      - conflict_handler -- String indicating how to handle conflicts
 |      - add_help -- Add a -h/-help option
 |      - allow_abbrev -- Allow long options to be abbreviated unambiguously
 |  
 |  Method resolution order:
 |      ArgumentParser
 |      _AttributeHolder
 |      _ActionsContainer
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  __init__(self, prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  add_subparsers(self, **kwargs)
 |      # ==================================
 |      # Optional/Positional adding methods
 |      # ==================================
 |  
 |  convert_arg_line_to_args(self, arg_line)
 |  
 |  error(self, message)
 |      error(message: string)
 |      
 |      Prints a usage message incorporating the message to stderr and
 |      exits.
 |      
 |      If you override this in a subclass, it should not return -- it
 |      should either exit or raise an exception.
 |  
 |  exit(self, status=0, message=None)
 |      # ===============
 |      # Exiting methods
 |      # ===============
 |  
 |  format_help(self)
 |  
 |  format_usage(self)
 |      # =======================
 |      # Help-formatting methods
 |      # =======================
 |  
 |  parse_args(self, args=None, namespace=None)
 |      # =====================================
 |      # Command line argument parsing methods
 |      # =====================================
 |  
 |  parse_known_args(self, args=None, namespace=None)
 |  
 |  print_help(self, file=None)
 |  
 |  print_usage(self, file=None)
 |      # =====================
 |      # Help-printing methods
 |      # =====================
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from _AttributeHolder:
 |  
 |  __repr__(self)
 |      Return repr(self).
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from _AttributeHolder:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from _ActionsContainer:
 |  
 |  add_argument(self, *args, **kwargs)
 |      add_argument(dest, ..., name=value, ...)
 |      add_argument(option_string, option_string, ..., name=value, ...)
 |  
 |  add_argument_group(self, *args, **kwargs)
 |  
 |  add_mutually_exclusive_group(self, **kwargs)
 |  
 |  get_default(self, dest)
 |  
 |  register(self, registry_name, value, object)
 |      # ====================
 |      # Registration methods
 |      # ====================
 |  
 |  set_defaults(self, **kwargs)
 |      # ==================================
 |      # Namespace default accessor methods
 |      # ==================================
目录
相关文章
|
Python 容器
【Python标准库】argparse的add_argument() 方法介绍
【Python标准库】argparse的add_argument() 方法介绍
|
机器学习/深度学习 存储
argparse库
argparse库
categorical_crossentropy与sparse_categorical_crossentropy的区别
categorical_crossentropy与sparse_categorical_crossentropy的区别
|
SQL Java 数据库连接
Parameter ‘XXX‘ not found.Available parameters are [arg2, arg1, arg0, param3, param1, param2]
当SQl语句的占位符和映射接口方法的参数名不一致时,需要将某个参数强行注入到某个占位符变量上时,可以使用@Param这个注解来标注映射的关系(@Param(“占位符的参数名”) 数据类型 自己定义的参数名)
356 0
Parameter ‘XXX‘ not found.Available parameters are [arg2, arg1, arg0, param3, param1, param2]
|
JSON 数据格式
parse 和parseObject 有什么区别
JSON.parse()返回的结果是Object对象
366 0
|
Python
argparse使用方法简单总结
argparse使用方法简单总结 argparse是python自带的命令行参数解析包,可以用来方便地读取命令行参数,当你的代码需要频繁地修改参数的时候,使用这个工具可以将参数和代码分离开来,让你的代码更简洁,适用范围更广。
412 0
GuessedAtParserWarning: No parser was explicitly specified,
GuessedAtParserWarning 一、问题描述 二、错误分析 二、解决方案
419 0
GuessedAtParserWarning: No parser was explicitly specified,