我正在为我的python项目编写config.ini
文件。我想提一下列的标准日期格式。
像这样的东西
prod_db_end_date = 2017-01-01
prod_db_end_date_format = %Y-%m-%d
但是它会插入其他内容并输出错误。有人可以告诉我如何使用它吗?
Error traceback - File "C:\ProgramData\Anaconda3\lib\configparser.py", line 443, in _interpolate_some
"found: %r" % (rest,))
configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%Y-%m-%d'
答案 0 :(得分:3)
您有三种选择:
禁用插值,或选择不同的插值处理程序。您可以将//div[@class='Tips' and text()='\u00a0']
选项设置为interpolation
以禁用整个文件的插值:
None
在禁用插值的情况下访问该特定值,为ConfigParser.get()
method设置ConfigParse(interpolation=None)
:
raw=True
将config.get('section', 'prod_db_end_date_format', raw=True)
个字符加倍%
:
%%