读取配置值的顺序是什么?

编程入门 行业动态 更新时间:2024-10-27 00:28:48
本文介绍了读取配置值的顺序是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对于我写的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

更多推荐

读取配置值的顺序是什么?

本文发布于:2023-11-25 08:02:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628960.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!