0

It works with digit list; I tried with single and double quote without success.

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)

Result:

Parse error from unrepr-ing value at line 2.  
Parse error from unrepr-ing value at line 2.
AstroCB
  • 12,337
  • 20
  • 57
  • 73
Mauricio
  • 670
  • 1
  • 8
  • 23

1 Answers1

0

With the unrepr set to true, you must indicate that Electric is given a string. So, you must write:

car1="""\
Number= 6
Electric= 'battery'
"""

car2= """\
Number= 8
Electric= 'solar_panel'
"""
Alf
  • 1
  • 1