title: Edit configuration file through python
body: <p>I need to edit a configuration file through python and i tried searching on stackoverflow and google and they don't cover my situation, since i need to replace lines in the file and perform matches in my search.</p>
  
  <p>Also, what i found covers how to do it for one line, i will be performing at least 8 line replacements in the file and I would like to know if there is a cleaner and more elegant way of doing this than putting 10 replace(foo, bar) lines altogether.</p>
  
  <p>I need to "match" lines like "ENABLEPRINTER", "PRINTERLIST", "PRNT1.PORT".
  I want to match thesse text and ignore whatever follows (ex: "=PRNT1, PRNT2").</p>
  
  <p>So i would do something like</p>
  
  <pre><code>replace('ENABLEPRINTER', 'y')
  replace('PRINTERLIST', 'PRNT3) 
  </code></pre>
  
  <p>The file looks like this:</p>
  
  <pre><code>ENABLEPRINTER=n
  PRINTERLIST=PRNT1, PRNT2
  
  PRNT1.PORT=9600
  PRNT1.BITS=8
  </code></pre>
  
  <p>Also note these files are about 100 lines and i need to edit about 10 of them.</p>
  
  <p>Thank you very much for your help. </p>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>Using the code posted by @J.F. Sebastian, i'm now getting the following error:</p>
  
  <pre><code>configobj.ParseError: Parse error in value at line 611.
  </code></pre>
  
  <p>Line 611 of the file is:</p>
  
  <pre><code>log4j.appender.dailyRollingFile.DatePattern='.'yyyy-MM-d
  </code></pre>
  
  <p>So the problem is with the ' character.</p>
  
  <p>If I comment out that line, the script is working fine with the code posted by @J.F. Sebastian.</p>