title: Editing a config file with python
body: <p>I am building a program that edits a <em><strong>.toml config</strong></em> file, take this for example:
  This is one of the sections from the entire .toml config file:</p>
  <pre><code>[APU]
  apu = &quot;any&quot;                   # Audio system. Use: [any, nop, sdl,xaudio2]
  </code></pre>
  <p>Normally the users changes the options manually for example if they want to change the apu they just replace the any inside quotation marks (&quot;&quot;) with xaudio2 for example.</p>
  <p>I want to create a code which presents the setting (apu = &quot; &quot;), and the options that the user has (any,xaudio,nop...)
  and let the user choose between the options.</p>
  <p>This was the code I originally wrote:</p>
  <pre><code>f = open(&quot;config.toml&quot;, &quot;r&quot;)
  fread = f.read()
  
  ### APU Options ###
  nop = fread.replace('apu = &quot;any&quot;', 'apu = &quot;nop&quot;')
  sdl = fread.replace('apu = &quot;any&quot;', 'apu = &quot;sdl&quot;')
  xaudio2 = fread.replace('apu = &quot;any&quot;', 'apu = &quot;xaudio2&quot;')
  
  
  ### Write the New File ####
  with open(&quot;config.toml&quot;, &quot;w&quot;) as f:
      f.write(xaudio2)
  </code></pre>
  <p>this code lacks something, when a user changes the apu to xaudio2 with this exact code, after the user re opens the program(this python code) for changing the apu again , the python code can not detect the original code since it <strong>was</strong>:</p>
  <pre><code>apu = &quot;any&quot;   
  
              
  </code></pre>
  <p>and now <strong>after</strong> the user has changed it to xaudio2 It will be this:</p>
  <pre><code>apu = &quot;xaudio2&quot;
  </code></pre>
  <p>the python code looks only for the apu = &quot;any&quot; to change and replace any with other options.
  What do you think is the solution? (when one of the settings in the config changes)</p>