Having options in argparse with a dash

前端 未结 5 1437
长发绾君心
长发绾君心 2020-12-12 18:58

I want to have some options in argparse module such as --pm-export however when I try to use it like args.pm-export I get the error that there is n

5条回答
  •  执笔经年
    2020-12-12 19:17

    Concise and explicit but probably not always acceptable way would be to use vars():

    #!/usr/bin/env python3
    
    import argparse
    
    parser = argparse.ArgumentParser()
    parser.add_argument('a-b')
    args = vars(parser.parse_args())
    
    print(args['a-b'])
    

提交回复
热议问题