Reading multiline values using ConfigParser

Phoe6 orsenthil at gmail.com
Wed Jun 20 12:50:31 EDT 2007


Hi,
I have a configfile, in fact, I am providing a configfile in the
format:

[Information]
Name: Foo
Author: Bar

Testcases:
tct123
tct124
tct101

The last values is a multi-line.

ConfigParser is unable to recognize a multi-line value and splits out
error.

C:\ATF-Tasks>python CreateTask.py
Traceback (most recent call last):
  File "CreateTask.py", line 13, in ?
    config.read('TaskDetails.txt')
  File "C:\Python24\lib\ConfigParser.py", line 267, in read
    self._read(fp, filename)
  File "C:\Python24\lib\ConfigParser.py", line 490, in _read
    raise e
ConfigParser.ParsingError: File contains parsing errors:
TaskDetails.txt
        [line 15]: 'tct123\n'
        [line 16]: 'tct124\n'
        [line 17]: 'tct101\n'

I am using ConfigParser in the following way:

config = ConfigParser.ConfigParser()
config.read('TaskDetails.txt')
config.get("Information","Testcases"):

Is there anyway, I can include multi-line value in the configfile? I
was thinking of following option:value for a portion of the file and
read the portion with multi-line as a normal file, but ConfigParser()
is not allowing multi-line value itself.

Any ideas/ Suggestions? :

Ofcourse, throw away ConfigParser and use your own parser is there,
but I would like to use that as the last option.

Thanks,
Senthil




More information about the Python-list mailing list