[Tutor] Problems with ConfigParser set method

Andreas Kostyrka andreas at kostyrka.org
Sun Mar 9 00:52:13 CET 2008


As I thought, it does not fail silently.

You need something like:

if not parser.has_section("feeds"):
    parser.add_section("feeds")

Andreas

Am Samstag, den 08.03.2008, 16:46 +0000 schrieb dave selby:
> Hi All,
> 
> I am using the ConfigParser module, I can 'get' from a config file
> fine, when I try to set it, it silently fails. the code.
> 
>         parser = ConfigParser.SafeConfigParser()
>         parser.read('./daemon.rc')
>         print parser.get('feeds', 'number')
>         parser.set('feeds', 'number',  '99')
>         print parser.get('feeds', 'number')
> 
> there is a section [feeds], and option number, it is set to 1. If I
> execute the script I get ...
> 
> dave at dev-machine:/var/lib/kmotion/daemons$ ./daemon_start.py
> 1
> 99
> dave at dev-machine:/var/lib/kmotion/daemons$ ./daemon_start.py
> 1
> 99
> dave at dev-machine:/var/lib/kmotion/daemons$
> 
> 
> The first call returns as expected, the second should return 99, 99
> not 1, 99. On opening daemons.rc the 'number' option is not changed.
> 
> Any ideas ?
> 
> Cheers
> 
> Dave
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20080309/8df7765f/attachment.pgp 


More information about the Tutor mailing list