[英]configparser : which encoding on windows?
My Python3 project works well on Linux but I got a problem with the configparser module on Windows. 我的Python3项目在Linux上运行良好,但在Windows上的configparser模块出现问题。 Every files of my own are encoded using UTF-8/unicode.
我自己的每个文件都使用UTF-8 / unicode编码。
The following code : 如下代码:
CONFIG_INI = configparser.ConfigParser()
CONFIG_INI.read( "config.ini" )
raises an error when launched from cmd.exe : 从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 ? 那么,为什么我的程序使用CP1252编码而不是unicode? I can't see on the configparser page how to set a specific encoding.
我在configparser 页面 上看不到如何设置特定的编码。
Any idea ? 任何想法 ? Thank you !
谢谢 !
In ConfigParser with Unicode items they offer: 在具有Unicode项目的ConfigParser中,它们提供:
cfg.readfp(codecs.open("myconfig", "r", "utf8"))
Have you tried that? 你有尝试过吗? Cheers!
干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.