STINNER Victor <[email protected]> added the comment:
Use utf_8_sig charset and open your file using io.open() or codecs.open() to
get unicode sections, options and values.
Example:
-------------------------------------
from ConfigParser import ConfigParser
import io
# create an utf-8 .ini file with a BOM marker
with open('bla.ini', 'wb') as fp:
fp.write(u'[section]\ncl\xe9=value'.encode('utf_8_sig'))
# read the .ini file
config = ConfigParser()
with io.open('bla.ini', 'r', encoding='utf_8_sig') as fp:
config.readfp(fp)
# dump the config
for section in config.sections():
print "[", repr(section), "]"
for option in config.options(section):
value = config.get(section, option)
print "%r=%r" % (option, value)
-------------------------------------
----------
nosy: +haypo
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue7519>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com