a ConfigParser wtf moment

Eric S. Johansson esj at harvee.org
Thu Jan 13 22:23:49 EST 2005


I'm not sure if this is a real problem or if I have been staring at code 
too long.  given this code

#!/usr/bin/python

from ConfigParser import *

configuration_file = "test.conf"
substitution = {"xyzzy":"maze"}
configuration = SafeConfigParser()
configuration.readfp(file(configuration_file))


list = configuration.items("core")
print list

list = configuration.items("core",0, substitution)
print list

---------------

and this configuration file

-----------

[core]
xyzzy=little bird
dwarf = greasy smoke %(xyzzy)s plugh

------------
why do I get the following results?

-------------

trial backup # python test.py
[('dwarf', 'greasy smoke little bird plugh'), ('xyzzy', 'little bird')]
[('dwarf', 'greasy smoke maze plugh'), ('xyzzy', 'maze')]
trial backup #

-------------

if you're having a hard time seeing it, before the substitution, xyzzy 
is set to the value in the configuration file, afterwards, it is set to 
the value of the substitution in the code.  It seems to me that 
substitutions should not affect any configuration file symbols of the 
same name.

anyway to fix this problem without python diving?

---eric




More information about the Python-list mailing list