读取配置值的顺序是什么? [英] What order of reading configuration values?

查看:239
本文介绍了读取配置值的顺序是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我写的python程序,我想给你机会以三种不同的方式配置它。环境变量,配置文件和命令行参数。

For the python program I am writing I would like to give the opportunity of configuring it in three different ways. Environment variables, configuration files and command line arguments.

逻辑上我认为命令行参数应该始终具有最高优先级。我有点怀疑环境变量是否应该优先于配置文件?

Logically I think command line arguments should always have the highest priority. I am a bit doubting whether environment variables should have precedence over configuration files? And will it matter whether configuration files are system wide, user specific or given as argument on the command line?

(注意我的平台是Unix / Linux)

(Note that my platform is Unix/Linux)

推荐答案

我知道的标准是首先查找命令行参数,如果没有找到环境var,然后本地配置文件然后全局配置文件。

The standard that I know is first look for a command line parameter, if not found environment var, then local config file then global config file.

所以当包安装在某处时。它将有一个默认的配置文件。这可以用本地配置文件更改。其中可以使用environ参数重写,然后命令行参数具有最高优先级。

So when a package is installed somewhere. It will have a default config file. This can be changed with a local config file. Which can be overrridden with a environ parameter and then the command line param has the highest precedence.

如果在命令行上声明了配置文件,那么它的内容将优先over environ params或任何其他配置文件。但命令行参数将优先于它。
但是请记住,搜索路径仍然存在。如果包正在寻找一个var它寻找。

If a config file is declared on the command line then its contents will take precedence over environ params or any other config files. But command line params will take precedence over it. But remember that the search path still exists. If the package is looking for a var it looks for.

Command line.
Config file thats name is declared on the command line.
Environment vars
Local config file (if exists)
Global config file (if exists)

我认为很多命令行编译器和Boost库config pak工作方式类似

I think many command line compilers and the Boost library config pak works in a similar fashion

这篇关于读取配置值的顺序是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆