简体   繁体   中英

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. 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:

UnicodeEncodeError: 'charmap' codec can't encode character '\˄' in position 13: character maps to

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.

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.

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.

For reference check

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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