ConfigParser and newlines

Minesh Patel minesh at gmail.com
Fri May 15 14:09:18 EDT 2009


I am using ConfigParser to parse a config file and I want to maintain
the newlines, how is it possible. Example given below. BTW, is there
an alternative to configParser, should I use 'exec' instead. Is there
any support for yaml built-in or possibly in the future?

test.cfg
============
[Foo_Section]

BODY = Line of text 1

   Continuing Line of text 1
============

Executing the code
===============
Python 2.5.1 Stackless 3.1b3 060516 (release25-maint, Mar  6 2009, 14:12:34)
[GCC 4.3.0 20080428 (Red Hat 4.3.0-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ConfigParser import RawConfigParser
>>> config = RawConfigParser()
>>> config.read('test.cfg')
['test.cfg']
>>> config.get('Foo_Section', 'BODY')
'Line of text 1\nContinuing Line of text 1'
>>>
===============

I was expecting 'Line of text 1\n\nContinuing Line of text 1'
                                               ^^^^
with 2 newlines, how can I achieve that with ConfigParser.



-- 
Thanks,
./Minesh



More information about the Python-list mailing list