简体   繁体   中英

configparser : which encoding on windows?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM