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?

  • this might help http://stackoverflow.com/questions/507123/python-3-0-how-to-make-print-output-unicode – Ashwini Chaudhary Jun 25 '12 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. – Lennart Regebro Jun 26 '12 at 11:54
  • See also: http://stackoverflow.com/a/30505612/788700 – Adobe May 28 '15 at 11:43

2 Answers2

4

Err... print them...

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

Windows will probably need chcp 65001 before running the script.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • 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" – Robert Sheldon Jun 25 '12 at 22:14
  • That would be a problem with that particular Python installation then. – Ignacio Vazquez-Abrams Jun 25 '12 at 22:15
  • 1
    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 – Robert Sheldon Jun 25 '12 at 22:33
  • Make sure to use the right encoding on your linux console... Check this question for more info [link](http://stackoverflow.com/questions/5306153/how-to-get-terminals-character-encoding) – golja Jun 25 '12 at 22:48
  • Support for cp65001 was added in Python3.3, but it still doesn't work right. – Mark Tolonen Jun 26 '12 at 00:39
  • I'm on W7 terminal and ipython, can't get emoji to display...missing my *unix environment. – wbg Feb 05 '15 at 16:46
3

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

>>> print('القاموس العربي')
القاموس العربي
Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504