14.7.7.2 替换错误
MAX_INTERPOLATION_DEPTH步骤之后替换停止,以避免递归引用导致的问题。
import configparser
parser = configparser.ConfigParser()
parser.add_section('sect')
parser.set('sect','opt','%(opt)s')
try:
print(parser.get('sect','opt'))
except configparser.InterpolationDepthError as err:
print('ERROR:',err)
如果有过多替换步骤,则会产生一个InterpolationDepthError异常。
缺少值会导致一个InterpolationMissingOptionError异常。
import configparser
parser = configparser.ConfigParser()
parser.add_section('bug_tracker')
parser.set('bug_tracker','url',
'http://%(server)s:%(port)s/bugs')
try:
print(parser.get('bug_tracker','url'))
except configparser.InterpolationMissingOptionError as err:
print('ERROR:',err)
由于没有定义server值,所以无法构造url。