它适用于数字列表;我尝试使用单引号和双引号但没有成功。
from configobj import ConfigObj, ConfigObjError
from io import StringIO
specs= """\
Number= [6, 8]
Electric= [`battery`, `solar_panel`]
"""
car1="""\
Number= 6
Electric= battery
"""
car2= """\
Number= 8
Electric= solar_panel
"""
class Processing():
def __init__(self, car):
super().__init__()
try:
ConfigObj(StringIO(car), configspec= StringIO(specs), unrepr= True)
except ConfigObjError as e:
print(e)
if __name__ == "__main__":
Processing(car1)
Processing(car2)
结果:
Parse error from unrepr-ing value at line 2.
Parse error from unrepr-ing value at line 2.