0

My script raises a UnicodeDecodeError when run in the Windows 8 console, but not when run in Eclipse/PyDev as a launch configuration. Where is the difference between the PyDev environment and running python.exe from the console in regards to unicode?

4

1 回答 1

5

不同之处在于默认编码。您可以通过 检索此信息sys.getdefaultencoding()。您会注意到 Windows 8 shell 中的默认编码是ascii,而 PyDev 将启动配置的默认编码默认为项目的默认编码,它本身默认为Cp1252.

有一些(有问题的)技巧可以更改代码中的默认编码,主要是reload(sys); sys.setdefaultencoding('myencoding'). Ian Bicking 在他的博文 The Illusive setdefaultencoding 中记录了这一点。

如果您只想将 PyDev 行为与您在控制台(或生产服务器上)中看到的内容对齐,您可以在启动配置属性的“通用”选项卡上更改默认编码:

在此处输入图像描述

于 2013-07-24T15:32:00.737 回答