The Python Oracle

Is there a way for a value from a config file to contain empty lines?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Horror Game Menu Looping

--

Chapters
00:00 Question
00:59 Accepted answer (Score 0)
01:26 Answer 2 (Score 0)
01:41 Thank you

--

Full question
https://stackoverflow.com/questions/1432...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python

#avk47



ANSWER 1

Score 0


\n is the escape code for a newline. Try using those instead.




ACCEPTED ANSWER

Score 0


The get interface provides substitutions that can be used for a suboptimal work around to the parser's strict handling of new lines:

> cat test.cfg 
[test] 
test=one%(nl)stwo%(nl)sthree

> cat test.py 
import ConfigParser
c = ConfigParser.SafeConfigParser()
c.read('test.cfg')
print c.get('test','test', vars={"nl":"\n\n"})

> python test.py 
one

two

three