View Full Version : [Python] ConfigParser doesn't reload my config file

January 15th, 2010, 12:29 AM
Hey guys,

I am creating a small program where I have a preferences dialog, I want the dialog to save preferences and then have them be reloaded by the main window. To achieve this I have created a file called arm_prefs.py

arm_prefs.py looks like this

import ConfigParser

config = ConfigParser.ConfigParser()
fname = open('config/preferences.conf', 'r')

def save_preferences():
fname2 = open('config/preferences.conf', 'w')

def set_preference(cat, sub, text):
config.set(cat, sub, text)

def get_preference(cat, sub):
return config.get(cat, sub)

pretty simple...

Well when my preferences dialog closes and I call get_preference from my main window it still uses the old value UNTIL I restart the program then it gets the correct value.

Any ideas?

January 15th, 2010, 11:56 AM
I think it has something to do with that pygtk needs to reload that window??? because when I open the preferences window again it has the new values.


January 18th, 2010, 02:36 PM
Turns out that it was because my init method only runs once meaning that the value from the config file is only read once which is at start-up.