My Python3 project works well on Linux but I got a problem with the configparser module on Windows. Every files of my own are encoded using UTF-8/unicode.

The following code :

    CONFIG_INI = configparser.ConfigParser()
    CONFIG_INI.read( "config.ini" )

raises an error when launched from cmd.exe :

    [..., from c:\Python33\lib\encodings\cp1252.py]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 [...]

So, why does my program use the CP1252 encoding instead of the unicode one ? I can't see on the configparser page how to set a specific encoding.

Any idea ? Thank you !

有帮助吗?

解决方案

In ConfigParser with Unicode items they offer:

cfg.readfp(codecs.open("myconfig", "r", "utf8"))

Have you tried that? Cheers!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top