日本系统上的Jython“未知编码ms932”

2024-10-02 18:21:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Jython 2.5.1编写了一个程序,它在我的windows7机器上运行得很好,但是在一台日本机器上,它抛出了一个异常:“unknown encoding‘ms932’”

我发现编解码器.java是唯一打印未知编码“xyz”消息的模块

此文件加载别名.py其中包含

# cp932 codec
'932'                : 'cp932',
'ms932'              : 'cp932',
'mskanji'            : 'cp932',
'ms_kanji'           : 'cp932',

文件cp932.py包含

^{pr2}$

但是。。_编解码器不存在as is also discussed in this page 有人知道从这里到哪里去吗?在

http://web.archiveorange.com/archive/v/8tc1Zc2rV3qiUcy9zPlA


Tags: 文件py程序机器消息编码编解码器jython
3条回答

您应该使用sys.setdefaultencoding,即

sys.setdefaultencoding(name)

或者干脆把

^{pr2}$

在你剧本的开头。在

Set the current default string encoding used by the Unicode implementation. If name does not match any available encoding, LookupError is raised. This function is only intended to be used by the site module implementation and, where needed, by sitecustomize. Once used by the site module, it is removed from the sys module’s namespace.

http://docs.python.org/library/sys.html

这是Jython Bugs问题#1066:

http://bugs.jython.org/issue1066

日语博客和其他什么都不推荐以下内容,对我也很有用:

用参数-C utf-8调用jython。在

请注意,显然仍然存在一些限制,例如无法访问日语路径名或将日语打印到控制台。我没有遇到过这些问题,所以我不能对解决方法发表评论。在

相关问题 更多 >