Python 和 Eclipse 上的 tkinter 中的字符集打印问题 +派德
我需要使用 Python 和 Tkinter 以不同语言使用和打印一些文本。 我在 Windows 和 Eclipse 上使用 Python 3.8.6 和 PyDev 插件。 在下面的示例中,我尝试用英语和意大利语打印几个字符串,但是当我尝试运行/调试时,它不会启动并产生此特定错误: UnicodeDecodeError:“utf-8”编解码器无法解码位置 384 中的字节 0xe0:无效的连续字节 任何帮助将不胜感激。
#---------------------------------------------------------------------------
# \file testutf8.py
# \brief
#
# \version rel. 1.0
# \date Created on 2022-03-25
# \author massimo
# Copyright (C) 2022 Massimo Manca - AIoTech
#---------------------------------------------------------------------------
#!/usr/local/bin/python
# encoding: utf-8
sa = "Penalty: "
sb = "Penalità: "
penalty = 10
strPenalty = sa + str(penalty)
print( strPenalty )
I need to use and print some text in different languages using Python and Tkinter.
I am using Python 3.8.6 on Windows and Eclipse with PyDev plugin.
In the following example I try to print a couple of strings in English and Italian but when I try to run/debug it does not start and produces this specific error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 384: invalid continuation byte
Any help will be appreciated.
#---------------------------------------------------------------------------
# \file testutf8.py
# \brief
#
# \version rel. 1.0
# \date Created on 2022-03-25
# \author massimo
# Copyright (C) 2022 Massimo Manca - AIoTech
#---------------------------------------------------------------------------
#!/usr/local/bin/python
# encoding: utf-8
sa = "Penalty: "
sb = "Penalità: "
penalty = 10
strPenalty = sa + str(penalty)
print( strPenalty )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要控制台使用的编码(在 Eclipse 中)和
PYTHONIOENCODING
匹配,一切都应该很好(只要您在Python 3
上打印str
即可)代码>)。我特别尝试确保所有内容都是
utf-8
,因此,请确保文本文件编码
在 Eclipse 内标记为这样:通常这应该足够了,因为其他设置是通常从那里派生,但您也可以仔细检查您的启动配置:
As long as the encoding used for the console (in Eclipse) and the
PYTHONIOENCODING
match, things should good (as far as you printstr
onPython 3
).I particularly try to make sure everything is
utf-8
, so, make sure that theText file encoding
is marked as such inside of Eclipse:Usually that should be enough as other settings are usually derived from there, but you can also double-check your launch configuration: