ConfigParser options spanning more than one line

J

Josh Close

I'm using ConfigParser and I can't seem to get a config option to span
more than one line.

[MyConfig]
var = blah blah blah\
blah continued

Putting the '\' doesn't work

Is there a way to do that? Or do I have to deal with having a huge
long string all on one line?

-Josh
 
N

Nick Patavalis

I'm using ConfigParser and I can't seem to get a config option to span
more than one line.

[MyConfig]
var = blah blah blah\
blah continued

Putting the '\' doesn't work

Is there a way to do that? Or do I have to deal with having a huge
long string all on one line?

Simply do:

[MyConfig]
var = blah blah blah
blah continued

without the '\'. Indentation continues the line.

/npat
 
P

Paramjit Oberoi

I'm using ConfigParser and I can't seem to get a config option to span
more than one line.
from ConfigParser import ConfigParser
from StringIO import StringIO
s = StringIO("[a]\n"
.... "b = 123\n"
.... " 456")'123\n456'

In other words, any line with a leading whitespace is considered a
continuation line, and the leading whitespace is stripped from the value
(but the carriage return is left in).

HTH,
-param
 
J

Josh Close

That works, I guess I'll just have to remove the \n from the variable then.

-Josh

I'm using ConfigParser and I can't seem to get a config option to span
more than one line.
from ConfigParser import ConfigParser
from StringIO import StringIO
s = StringIO("[a]\n"
.... "b = 123\n"
.... " 456")'123\n456'

In other words, any line with a leading whitespace is considered a
continuation line, and the leading whitespace is stripped from the value
(but the carriage return is left in).

HTH,
-param
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top