#!/usr/bin/env python
#coding:utf-8


from  argparse import ArgumentParser


#----------------------------------------------------------------------
def test(zzz):
    """"""

    print zzz


if __name__ == '__main__':

    parse = ArgumentParser()
    parse.add_argument("-a",type=str)

    args=parse.parse_args()
    print args.a

    print  "111"

test.py -a abc输出如下:

python 参数解析ArgumentParser

 

parser.add_argument('-c', action='store_true', default=false)

#python test.py -c => c是true(因为action)
#python test.py => c是false(default)

 

相关文章:

  • 2022-12-23
  • 2021-10-11
  • 2017-12-02
  • 2022-12-23
  • 2022-01-01
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-02
  • 2021-11-08
  • 2021-08-22
  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
相关资源
相似解决方案