Python configparser reading section and creating new config
<p>I'm currently reading a config file getting all values from a specific section and printing them however, instead of printing them I would like to create a new config file with just that section I am reading. </p>

<p>How would I go about this?</p>

<p>code</p>

<pre><code>configFilePath = 'C:\\testing.ini'
config = ConfigParser.ConfigParser()
    config.optionxform = str
    config.read(configFilePath)
    section = 'testing1'
    configdata = {k:v for k,v in config.items(section)}
    for x in configdata.items(): 
        print x[0] + '=' + x[1]
</code></pre>

<p>config ini</p>

<pre><code>[testing1]
EspaÃ±ol=spain
UK=unitedkingdom
something=somethingelse

[dontneed]
dontneedthis=blahblah
dontneedthis1=blahblah1
</code></pre>

<p>Also while I'm here, I'm not sure how I would get this to work with encoded strings like "Ã±" as it errors, however I need my new config file exactly how I'm reading it.</p>

<p>I got it working with </p>

<pre><code>for x in configdata.items(): 
    confignew.set(section,x[0],x[1]) 
confignew.write( EqualsSpaceRemover( cfgfile ) ) 
</code></pre>

<p>however, how would I edit my code so it can read text with characters like " Ã± " and parse/write them without getting errors about decode problems?</p>

python parsing configparser python-config