[issue31535] configparser unable to write comment with a upper cas letter
Karthikeyan Singaravelan
report at bugs.python.org
Tue Sep 11 07:15:23 EDT 2018
Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:
All config options are converted to lowercase when they are stored. You can customise this with https://docs.python.org/3/library/configparser.html#configparser.ConfigParser.optionxform. You can customize it more with https://docs.python.org/3/library/configparser.html#customizing-parser-behaviour
> Note also that keys in sections are case-insensitive and stored in lowercase
>>> from configparser import ConfigParser
>>> c = ConfigParser()
>>> c["A"] = {'FOO': 'bar'}
>>> with open('example.ini', 'w') as configfile: c.write(configfile)
...
>>> with open('example.ini', 'r') as configfile: print(configfile.read())
...
[A]
foo = bar
# Don't convert to lower case
>>> d = ConfigParser()
>>> d.optionxform = str
>>> d["A"] = {'FOO': 'bar'}
>>> with open('example_case.ini', 'w') as configfile: d.write(configfile)
...
>>> with open('example_case.ini', 'r') as configfile: print(configfile.read())
...
[A]
FOO = bar
Hope this answers your question. Feel free to close this if it's clear.
Thanks
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31535>
_______________________________________
More information about the Python-bugs-list
mailing list