简体   繁体   English

Python 和 tkinter 在 Eclipse + PyDev 上的字符集打印问题

[英]Problem on charset print in Python and tkinter on Eclipse + PyDev

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.我需要使用 Python 和 Tkinter 使用和打印一些不同语言的文本。我在 Windows 和 Eclipse 上使用 Python 3.8.6 和 PyDev 插件。 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.在下面的示例中,我尝试用英语和意大利语打印几个字符串,但是当我尝试运行/调试时,它不会启动并产生此特定错误:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 384: invalid continuation byte 任何帮助将不胜感激。

#---------------------------------------------------------------------------
# \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 )

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 ).只要用于控制台的编码(在 Eclipse 中)和PYTHONIOENCODING匹配,事情就应该是好的(就您在Python 3上打印str而言)。

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:我特别尝试确保一切都是utf-8 ,因此,确保Text file encoding在 Eclipse 中被标记为这样:

文本文件编码

Usually that should be enough as other settings are usually derived from there, but you can also double-check your launch configuration:通常这应该足够了,因为其他设置通常来自那里,但您也可以仔细检查您的启动配置:

启动编码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM