Koz*_*zaK 3 python configuration-files configparser
我想使用配置文件和一些简单的数学表达式,如添加或减少.
例如:
[section]
a = 10
b = 15
c = a-5
d = b+c
Run Code Online (Sandbox Code Playgroud)
有没有办法使用ConfigParser模块?我发现了一些在配置文件中使用字符串作为变量的例子,但如果我使用它,我会得到一个未计算的字符串(我必须在我的python代码中解析它).
如果在ConfigParser中不可能,您推荐使用任何模块吗?
为什么要使用ConfigParser?为什么不呢
config.py:
a = 10
b = 15
c = a-5
d = b+c
Run Code Online (Sandbox Code Playgroud)
script.py:
import config
print(config.c)
# 5
print(config.d)
# 20
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2336 次 |
| 最近记录: |