473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ConfigParser options spanning more than one line

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
Jul 18 '05 #1
3 4021
On 2004-08-16, Josh Close <na****@gmail.com> wrote:
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
Jul 18 '05 #2
> 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") c=ConfigParser()
c.readfp(s)
c.get('a','b')

'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
Jul 18 '05 #3
That works, I guess I'll just have to remove the \n from the variable then.

-Josh

On Mon, 16 Aug 2004 13:31:03 -0500, Paramjit Oberoi
<p_********@hotmail.com> wrote:
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") c=ConfigParser()
c.readfp(s)
c.get('a','b')

'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
--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Martin Maney | last post by:
Summary: with batteries like these, get a longer extension cord? <transcript from interactive session> Python 2.2.1 (#1, Sep 7 2002, 14:34:30) on linux2 Type "help", "copyright",...
3
by: S.Ramaswamy | last post by:
I am trying unsuccessfully to set the order of options using the set(section,option,value) method ( Python 2.2.2) and writing to a file. But the options always appear in a random order. Before...
1
by: David Rysdam | last post by:
I have a file test.cfg: option1=foo option2=bar I have a program testconfig.py: import ConfigParser
1
by: Robin Munn | last post by:
I've been loving SQLObject. The ability to set up a database connection and then completely *forget* about it and just manipulate Python objects has been great. But I'm running into a problem, and...
3
by: Sergey | last post by:
Is there an alternative to standard module ConfigParser, which can use delimitier symbol other than ":" and "=", preferaby just space? I need to parse such configs: 2:5020/758 xxxx 2:5020/794...
1
by: pipehappy | last post by:
Hello everyone: I came across the module ConfigParser and can use it correctly. import ConfigParser fp = open('test.cfg','w+') config = ConfigParser.ConfigParser() config.readfp(fp)...
3
by: derf912 | last post by:
I am working with ConfigParser in python and the ini file that I am reading in has a section titled and under that section I have multiple options. All the options have the same name "customer =" ...
4
by: Phoe6 | last post by:
Hi, I have a configfile, in fact, I am providing a configfile in the format: Name: Foo Author: Bar Testcases: tct123
3
by: Phoe6 | last post by:
Hi, Am starting a new thread as I fear the old thread which more than a week old can go unnoticed. Sorry for the multiple mails. I took the approach of Subclassing ConfigParser to support...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.