The Python Oracle

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

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------


Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Jungle Looping

--

Chapters
00:00 Is There A Way For A Value From A Config File To Contain Empty Lines?
00:42 Answer 1 Score 0
00:53 Accepted Answer Score 0
01:09 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