title: ConfigParser - Writing to .ini file
body: <p>I have a config.ini file that has some default configuration for a web app (Flask using VS 2017)</p>
  
  <p>I also want to write some configuration myself.</p>
  
  <p>I am using the below code to try to write in the <code>[keys]</code> section, the variable being <code>gkey</code>:</p>
  
  <pre><code>def writeKey(key):
      Config = configparser.ConfigParser()    
      configFile = Path("config.ini")
      if configFile.is_file() == False:
          cfgfile = open("config.ini",'w')
      else:
          cfgfile = open("config.ini")
  
      # add the settings to the structure of the file, and lets write it out...
      Config.add_section('keys')
      Config.set('gkey','key',True)
      Config.write(cfgfile)
      cfgfile.close()
  
  gkey = encrypt(key)
  writeKey(gkey)
  </code></pre>
  
  <p>I get the below error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\blivo\documents\visual studio 2017\Projects\blivori2\blivori2\blivori2\functions\common.py", line 59, in &lt;module&gt;
      writeKey(gkey)
    File "C:\Users\blivo\documents\visual studio 2017\Projects\blivori2\blivori2\blivori2\functions\common.py", line 30, in writeKey
      Config.set('gkey','key',True)
    File "C:\Program Files\Python36\lib\configparser.py", line 1189, in set
      self._validate_value_types(option=option, value=value)
    File "C:\Program Files\Python36\lib\configparser.py", line 1174, in _validate_value_types
      raise TypeError("option values must be strings")
  TypeError: option values must be strings
  </code></pre>
  
  <p>I would like to ask a question:</p>
  
  <ul>
  <li>Would it be appropriate to store configuration in an .ini file? If so, how is the best way to protect it from being read/exposed to the public.</li>
  </ul>