0
# -*- coding: utf-8 -*-
import sys
from io import TextIOWrapper
sys.stdout = TextIOWrapper(sys.stdout.buffer, encoding='UTF-8', errors='replace')

print('♥')

I have problems with printing out the suits symbols in Windows console I search the internet for 2 days but found nothing how to make the console able to print these symbols. It seems to work in any other platform like Linux... I tried the solution provided above to import some modules and change the encoding of the system. it works but after 2 hours the console starts printing Latin characters instead e.g ē Does not make any sense i really need help i have to do this before the submition day on next friday

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
Faisal Julaidan
  • 388
  • 4
  • 16

1 Answers1

0

(1) Set PYTHONIOENCODING system variable:

 set "PYTHONIOENCODING=UTF-8"

(2) Change the active console Code Page to UTF-8.

Script (note that all the sys.stdout = … stuff is commented out):

# -*- coding: utf-8 -*-
# import sys
# from io import TextIOWrapper
# sys.stdout = TextIOWrapper(sys.stdout.buffer, encoding='UTF-8', errors='replace')

print('♥')

Output (Copy&Paste from an open cmd window):

==> set pyth
PYTHONIOENCODING=UTF-8

==> chcp
Active code page: 852

==> D:\test\Python\40496821.py
ÔÖą

==> chcp 437
Active code page: 437

==> D:\test\Python\40496821.py
ΓÖÑ

==> chcp 65001
Active code page: 65001

==> D:\test\Python\40496821.py
♥

==>
JosefZ
  • 28,460
  • 5
  • 44
  • 83
  • sorry, but I did not get what you mean by changing the active console mode – Faisal Julaidan Nov 08 '16 at 22:27
  • @FaisalJulaidan please [edit your question](http://stackoverflow.com/posts/40496821/edit) and provide what do you get for various `chcp`s (like I did). Read [Changing default encoding of Python?](http://stackoverflow.com/questions/2276200/changing-default-encoding-of-python). – JosefZ Nov 08 '16 at 22:38
  • On Windows 7, that causes `LookupError: unknown encoding: cp65001` in Python. – zvone Nov 08 '16 at 22:44