<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. 解析配置文件、环境和命令行参数,以获取单个选项集合

        时间:2023-07-04
      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.

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

                  上一篇:打开命令行时Windows环境变量发生变化? 下一篇:os.getenv 和 os.environ.get 的区别

                  相关文章

                  1. <small id='kknq7'></small><noframes id='kknq7'>

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

                  2. <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>
                      <legend id='kknq7'><style id='kknq7'><dir id='kknq7'><q id='kknq7'></q></dir></style></legend>