<i id='85dcd'><tr id='85dcd'><dt id='85dcd'><q id='85dcd'><span id='85dcd'><b id='85dcd'><form id='85dcd'><ins id='85dcd'></ins><ul id='85dcd'></ul><sub id='85dcd'></sub></form><legend id='85dcd'></legend><bdo id='85dcd'><pre id='85dcd'><center id='85dcd'></center></pre></bdo></b><th id='85dcd'></th></span></q></dt></tr></i><div id='85dcd'><tfoot id='85dcd'></tfoot><dl id='85dcd'><fieldset id='85dcd'></fieldset></dl></div>

<small id='85dcd'></small><noframes id='85dcd'>

      • <bdo id='85dcd'></bdo><ul id='85dcd'></ul>
    1. <tfoot id='85dcd'></tfoot>
      <legend id='85dcd'><style id='85dcd'><dir id='85dcd'><q id='85dcd'></q></dir></style></legend>

      1. 解析配置文件、环境和命令行参数,以获取单个选项集合

        Parse config files, environment, and command-line arguments, to get a single collection of options(解析配置文件、环境和命令行参数,以获取单个选项集合)
      2. <small id='aS2yv'></small><noframes id='aS2yv'>

          <bdo id='aS2yv'></bdo><ul id='aS2yv'></ul>

              <tbody id='aS2yv'></tbody>
              • <tfoot id='aS2yv'></tfoot>

                  <i id='aS2yv'><tr id='aS2yv'><dt id='aS2yv'><q id='aS2yv'><span id='aS2yv'><b id='aS2yv'><form id='aS2yv'><ins id='aS2yv'></ins><ul id='aS2yv'></ul><sub id='aS2yv'></sub></form><legend id='aS2yv'></legend><bdo id='aS2yv'><pre id='aS2yv'><center id='aS2yv'></center></pre></bdo></b><th id='aS2yv'></th></span></q></dt></tr></i><div id='aS2yv'><tfoot id='aS2yv'></tfoot><dl id='aS2yv'><fieldset id='aS2yv'></fieldset></dl></div>

                1. <legend id='aS2yv'><style id='aS2yv'><dir id='aS2yv'><q id='aS2yv'></q></dir></style></legend>
                  本文介绍了解析配置文件、环境和命令行参数,以获取单个选项集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Python 的标准库有用于配置文件解析的模块(configparser),环境变量读取(os.environ),以及命令行参数解析(argparse).我想编写一个程序来完成所有这些,并且:

                  Python's standard library has modules for configuration file parsing (configparser), environment variable reading (os.environ), and command-line argument parsing (argparse). I want to write a program that does all those, and also:

                  • 具有选项值的级联:

                  • 默认选项值,被覆盖
                  • 配置文件选项,被
                  • 覆盖
                  • 环境变量,被
                  • 覆盖
                  • 命令行选项.

                  允许在命令行中指定一个或多个配置文件位置,例如--config-file foo.conf,并读取它(代替或附加到通常的配置文件).这仍然必须遵守上述级联.

                  Allows one or more configuration file locations specified on the command line with e.g. --config-file foo.conf, and reads that (either instead of, or additional to, the usual configuration file). This must still obey the above cascade.

                  允许在一个地方定义选项来确定配置文件和命令行的解析行为.

                  Allows option definitions in a single place to determine the parsing behaviour for configuration files and the command line.

                  将已解析的选项统一为一个选项值的单一集合,以供程序的其余部分访问,而无需关心它们来自何处.

                  Unifies the parsed options into a single collection of option values for the rest of the program to access without caring where they came from.

                  我需要的一切显然都在 Python 标准库中,但它们不能顺利协同工作.

                  Everything I need is apparently in the Python standard library, but they don't work together smoothly.

                  如何在与 Python 标准库的偏差最小的情况下实现这一目标?

                  How can I achieve this with minimum deviation from the Python standard library?

                  推荐答案

                  似乎标准库没有解决这个问题,让每个程序员都在拼凑 configparserargparseos.environ 以笨拙的方式组合在一起.

                  It seems the standard library doesn't address this, leaving each programmer to cobble configparser and argparse and os.environ all together in clunky ways.

                  这篇关于解析配置文件、环境和命令行参数,以获取单个选项集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)
                    1. <small id='kknq7'></small><noframes id='kknq7'>

                          <bdo id='kknq7'></bdo><ul id='kknq7'></ul>

                        • <tfoot id='kknq7'></tfoot>

                            <i id='kknq7'><tr id='kknq7'><dt id='kknq7'><q id='kknq7'><span id='kknq7'><b id='kknq7'><form id='kknq7'><ins id='kknq7'></ins><ul id='kknq7'></ul><sub id='kknq7'></sub></form><legend id='kknq7'></legend><bdo id='kknq7'><pre id='kknq7'><center id='kknq7'></center></pre></bdo></b><th id='kknq7'></th></span></q></dt></tr></i><div id='kknq7'><tfoot id='kknq7'></tfoot><dl id='kknq7'><fieldset id='kknq7'></fieldset></dl></div>
                              <tbody id='kknq7'></tbody>
                            <legend id='kknq7'><style id='kknq7'><dir id='kknq7'><q id='kknq7'></q></dir></style></legend>