hen*_*ekk 4 python configparser python-3.x
我试图使用python 3.6或python 3.5.1中标准库中的configparser模块
我的ini文件看起来像这样:
[common]
domain = http://some_domain_name:8888
about = about/
loginPath = /accounts/login/?next=/home
fileBrowserLink = /filebrowser
partNewDirName = some_dir
[HUE_310]
partNewFilePath = ${common:domain}
Run Code Online (Sandbox Code Playgroud)
我的“主”程序如下所示:
from configparser import ConfigParser
parser = ConfigParser()
parser.read('configfile.ini')
lll = parser.get('HUE_310', 'partNewFilePath')
print(lll)
Run Code Online (Sandbox Code Playgroud)
相反,http://some_domain_name:8888我得到了${common:domain}
我将Pycharm社区用作我的IDE。我使用virtualenv。
我不知道我的代码有什么问题...
如果要扩展插值,则必须创建configparser.ExtendedInterpolation类的实例,方法是调用,然后interpolation=在创建ConfigParser实例时将其与关键字参数一起使用,如下所示:
from configparser import ConfigParser, ExtendedInterpolation
parser = ConfigParser(interpolation=ExtendedInterpolation())
parser.read('configfile.ini')
lll = parser.get('HUE_310', 'partNewFilePath')
print(lll) # -> http://some_domain_name:8888
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2201 次 |
| 最近记录: |