ConfigParser and newlines

M

Minesh Patel

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.
 
M

Mike Driscoll

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?

The primary alternative to ConfigParser is Michael Foord's ConfigObj:

http://www.voidspace.org.uk/python/configobj.html

I don't know if it has yaml support or not though.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top