ConfigParser与导入配置 [英] ConfigParser vs. import config

查看:172
本文介绍了ConfigParser与导入配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ConfigParser 很多争论的用于Python的香草配置解析器。

不过,您可以简单地 import config 其中 config.py 有设置配置参数的python代码。

ConfigParser is the much debated vanilla configuration parser for Python.
However you can simply import config where config.py has python code which sets configuration parameters.

这两种配置方法的优点是什么?
我应该何时选择每一个?

What are the pros\cons of these two approaches of configuration? When should I choose each?

推荐答案

/ code>是您不知道在导入时会发生什么 。是的,你会得到一组自然引用的符号,使用样式界面。但是在配置文件中的代码也可以做谁知道什么。现在,如果你完全信任你的用户,然后允许他们做任何他们在配置文件中的感觉可能是一件好事。但是,如果您有未知的数量,或者您想要保护用户免受自己的攻击,则使用更传统格式的配置文件将更安全,更安全。

The biggest issue I see with import config is that you don't know what will happen when you import it. Yes, you will get a set of symbols that are naturally referenced using a . style interface. But the code in the configuration file can also do who-knows-what. Now, if you completely trust your users, then allowing them to do whatever they feel like in the config file is possibly a good thing. However, if you have unknown quantities, or you want to protect users from themselves, then having a configuration file in a more traditional format will be safer and more secure.

这篇关于ConfigParser与导入配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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