[Tutor] Config Parser question

Kent Johnson kent37 at tds.net
Sat Oct 8 03:21:29 CEST 2005


Alberto Troiano wrote:
> Let me get this straight.. In order to store the new configuration I would
> have to make something like this?
> 
> import ConfigParser
> 
> f=open("config.ini","w+")
I would use 'w' but to tell the truth I'm not to clear on the difference between 'w' and 'w+'

> c=ConfigParser.ConfigParser()
> c.add_section("foo")
you might want 
  c.set('foo', 'bar', 'baz')

> c.write(f)
> 
> Please let me know if this is correct

I think so. Why not try it?

Kent
> 
> Thank you
> 
> Alberto
> 
> -----Mensaje original-----
> De: Kent Johnson [mailto:kent37 at tds.net] 
> Enviado el: Viernes, 07 de Octubre de 2005 18:36
> Para: Alberto Troiano
> CC: tutor at python.org
> Asunto: Re: [Tutor] Config Parser question
> 
> Alberto Troiano wrote:
> 
>>I'm trying to make a configuration file
>>
>>I know how to read the sections and options (using ConfigParser module 
>>from Python 2.3.4 on Win XP)
>>
>>What I wanted to know is that eventually I will need to add sections and 
>>options or change values or erase options or , etc
>>
>>Is there any way that I can do this changes to the config.ini file?
> 
> 
> Sure. See the docs for RawConfigParser add_section(), set() and write().
> ConfigParser is a subclass of RawConfigParser so you can use any of these
> methods.
> http://docs.python.org/lib/RawConfigParser-objects.html
> 
> Kent
> 
> 
> 
> 



More information about the Tutor mailing list