473,698 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4048
On 2004-08-16, Josh Close <na****@gmail.c om> 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_********@hot mail.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
1822
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", "credits" or "license" for more information. >>> from ConfigParser import ConfigParser >>> cp = ConfigParser()
3
3594
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 each option I am writing a comment line using set(section,"#",value) - a one line explanation for the option that follows - but the comments get re-ordered randomly. ...
1
1631
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
1630
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 I'd like some advice. I'm writing an app using SQLite as the database backend, and interfacing to it via SQLObject. I have all my SQL table definitions (classes inheriting from SQLObject) in one module, and for simplicity's sake I'm using a...
3
683
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 yyyy ConfigParser is not able to work with option names which contain symbol ':' It is not difficult to modify ConfigParser to resolve it, but may be another
1
2015
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) config.add_section('test') config.set('test', 'haha', 'hehe')
3
7187
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 =" Eample: customer = widget1 customer = widget2 customer = widget3 customer = widget4 I am trying to get a list of all the options but have only been able to get the last one to print. Here is the script that I am working with right...
4
14246
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
2840
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 multiline values without leading white-spaces, but am struct at which position in _read I should modify to accomodate the non-leading whitespace based multiline values.
0
9032
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6532
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.