title: Python ConfigParser persist configuration to file
body: <p>I have a configuration file (feedbar.cfg), having the following content:</p>
  
  <pre><code>[last_session]
  last_position_x=10
  last_position_y=10
  </code></pre>
  
  <p>After I run the following python script:</p>
  
  <pre><code>#!/usr/bin/env python
  
  import pygtk
  import gtk
  import ConfigParser
  import os
  pygtk.require('2.0')
  
  class FeedbarConfig():
   """ Configuration class for Feedbar.
   Used to persist / read data from feedbar's cfg file """
   def __init__(self, cfg_file_name="feedbar.cfg"):
    self.cfg_file_name = cfg_file_name
    self.cfg_parser = ConfigParser.ConfigParser()
    self.cfg_parser.readfp(open(cfg_file_name))
  
   def update_file(self):
    with open(cfg_file_name,"wb") as cfg_file:
     self.cfg_parser.write(cfg_file)
  
   #PROPERTIES 
   def get_last_position_x(self):
    return self.cfg_parser.getint("last_session", "last_position_x")
   def set_last_position_x(self, new_x):
    self.cfg_parser.set("last_session", "last_position_x", new_x)
    self.update_file()
  
   last_position_x = property(get_last_position_x, set_last_position_x)
  
  if __name__ == "__main__":
   #feedbar = FeedbarWindow()
   #feedbar.main()
   config = FeedbarConfig()
   print config.last_position_x
   config.last_position_x = 5
   print config.last_position_x
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>10
  5
  </code></pre>
  
  <p>But the file is not updated. The cfg file contents remain the same.</p>
  
  <p>Any suggestions ?</p>
  
  <p>Is there another way to bind config information from a file into a python class ? Something like JAXB in Java (but not for XML, just .ini files).</p>
  
  <p>Thanks!</p>