4

I'm currently writing a 2-player chess game for the terminal and I'd like to be able to print the actual unicode characters for the pieces (for instance, http://en.wikipedia.org/wiki/Rook_(chess)#Unicode). How would one go about printing actual unicode representations in python 3 instead of escape characters? does the charset of the terminal need to be changed (I primarily use windows and linux), and can that be done by a system call in the program itself?

3
  • this might help stackoverflow.com/questions/507123/… Commented Jun 25, 2012 at 22:25
  • Having anything else than line printing of ascii and making it work in both Windows terminal and Linux terminals needs a library. UniCurses is a Python library that wraps curses/PDCurses. I haven't used it, but it might be worth a try. Commented Jun 26, 2012 at 11:54
  • See also: stackoverflow.com/a/30505612/788700 Commented May 28, 2015 at 11:43

2 Answers 2

4

Err... print them...

3>> print('♔♕♖')
♔♕♖

Windows will probably need chcp 65001 before running the script.

Sign up to request clarification or add additional context in comments.

6 Comments

After executing chcp 65001 I get this error when trying to run Python: "Fatal Python error: Py_Initialize: can't initialize sys standard streams LookupError: unknown encoding: cp65001"
That would be a problem with that particular Python installation then.
it looks like this is going to be a linux-only program. Windows terminal seems to be very tetchy with nonasci, I can't even echo those characters in the terminal after I change to 65001, it just exits. Thanks for your input
Make sure to use the right encoding on your linux console... Check this question for more info link
Support for cp65001 was added in Python3.3, but it still doesn't work right.
|
3

Python 3 doesn't need anything extra for that, just use print().

>>> print('القاموس العربي')
القاموس العربي

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.