On top of the core functionality,
SafeConfigParser supports
interpolation. This means values can
contain format strings which refer to
other values in the same section, or
values in a special DEFAULT section.
Additional defaults can be provided on
initialization.
For example:
[My Section]
foodir: %(dir)s/whatever
dir=frob
long: this value continues
in the next line
would resolve the %(dir)s to the value
of dir (frob in this case). All
reference expansions are done on
demand.
可以使用ConfigParser插值
你的例子变成:
写“%(foo)s”,而不是“${foo}”。(参见http://docs.python.org/library/configparser.html并搜索“插值”。这适用于普通的ConfigParser或SafeConfigParser。)
在Python 3中,您可以使用
${base_dir}/bin
,而extended interpolation允许您使用来自其他部分的变量。示例:相关问题 更多 >
编程相关推荐