Python 和 Eclipse 上的 tkinter 中的字符集打印问题 +派德

发布于 2025-01-16 22:40:05 字数 686 浏览 3 评论 0原文

我需要使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绻影浮沉 2025-01-23 22:40:05

只要控制台使用的编码(在 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 print str on Python 3).

I particularly try to make sure everything is utf-8, so, make sure that the Text file encoding is marked as such inside of Eclipse:

Text file encoding

Usually that should be enough as other settings are usually derived from there, but you can also double-check your launch configuration:

Launch encoding

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文