Setting options from environment variables when using argparse

后端 未结 12 1988
执念已碎
执念已碎 2020-12-08 04:06

I have a script which has certain options that can either be passed on the command line, or from environment variables. The CLI should take precedence if both are present, a

12条回答
  •  醉梦人生
    2020-12-08 04:51

    ConfigArgParse adds support for environment variables to argparse, so you can do things like:

    p = configargparse.ArgParser()
    p.add('-m', '--moo', help='Path of cow', env_var='MOO_PATH') 
    options = p.parse_args()
    

提交回复
热议问题