Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to write special value to a config file with ConfigParser

Reply
Thread Tools

how to write special value to a config file with ConfigParser

 
 
Lialie
Guest
Posts: n/a
 
      04-23-2006

Hello,all
I found it easy to read configures from a config file.
But how can I set a special value to an item or write it into the
original file?
I have tried this:

import ConfigParser
config = ConfigParser.ConfigParser()
config.read('a.conf')
config.get('Main', 'Something') # That is OK.
config.set('Main', 'Something', '2') # without any fault
#fp = open('a.conf') # can not be done, raise Error
#fp = open('a.conf', 'a') # Something set to 2, but it copies the all items
#config.write(fp)


# How can I do it?

 
Reply With Quote
 
 
 
 
pavel.starek@gmail.com
Guest
Posts: n/a
 
      04-23-2006
Hi,

I have tried this:

<pre>
import ConfigParser
fp = file("test.conf","w+")
cp = ConfigParser.ConfigParser()
cp.add_section("Section1")
cp.set("Section1","Value1",12345)
cp.write(fp)
</pre>

and works fine for me.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Config & ConfigParser Chuck Python 11 03-07-2013 04:18 PM
ConfigParser: Can I read(ConfigParser.get()) a configuration file anduse it to call a funciton? jamitwidme@gmail.com Python 3 06-26-2008 08:01 PM
Any other config parsing modules besides ConfigParser ? Arthur Pemberton Python 2 05-29-2006 03:40 PM
[ConfigParser] value with ; and the value blank kai Python 1 05-05-2006 05:18 PM



Advertisments