简体   繁体   English

在Python的命令行中使用Unicode字符(Python 3.4.1)

[英]Using unicode characters in Python's command line (Python 3.4.1.)

I want to develop a Python application (I am using Python 3.4.1.) that deals with logic, and therefore I need to print some Unicode symbols, like the “and” symbol. 我想开发一个处理逻辑的Python应用程序(我正在使用Python 3.4.1),因此我需要打印一些Unicode符号,例如“ and”符号。 When I run the program in Python's shell I don't have problems printing the characters, but when I try to run it on Python's command line, this error appears: 当我在Python的Shell中运行程序时,我不会出现打印字符的问题,但是当我尝试在Python的命令行上运行该程序时,会出现以下错误:

UnicodeEncodeError: 'charmap' codec can't encode character '\˄' in position 13: character maps to UnicodeEncodeError:'charmap'编解码器无法在位置13编码字符'\\ u02c4':字符映射到

Do you know if it is possible to print these characters in the command line? 您知道是否可以在命令行中打印这些字符吗?

If it is possible, how can I do it? 如果有可能,我该怎么办?

Thank you in advance for your attention. 预先感谢您的关注。

This will depend on the encoding of the terminal you are using - One of the most complete encodings is utf-8, and if you ensure your terminal is on utf-8 you should have no problem printing these characters. 这将取决于您使用的终端的编码-最完整的编码之一是utf-8,如果您确保终端使用的是utf-8,则打印这些字符应该没有问题。

The "charmap" encoding is used on the windows terminal - and can only didplay a subset of 256 unicode characters - which do not include '\˄', among possibly others you might want. Windows终端使用“ charmap”编码-只能播放256个unicode字符的子集-不包括'\\ u02c4',可能还包括其他字符。

There is nothing you can do on the Python side, but for changing your app to open an application window using Tkinter or another graphic toolkit. 在Python方面,您无能为力,只能使用Tkinter或其他图形工具包更改应用程序以打开应用程序窗口。

For reference check 供参考检查

https://wiki.python.org/moin/PrintFails https://wiki.python.org/moin/PrintFails

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

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