Skip to content Skip to sidebar Skip to footer

Printing Non-ascii Characters In Python 3

So I want to print special characters like ® (the Reserved Sign char). Seems easy enough. I found someone else trying to do the same thing but with the copyright symbol and gave i

Solution 1:

The reason it only errors out when you try to print to windows cmd is because cmd itself does not support that character. See:

  1. this other stack overflow question asking basically the same thing.

  2. @Martijn Pieters comment linking to a python.org site addressing print failures, which explains that on Windows,

  3. the supported characters are now more naitive to the OS, and the Copyright Sign and Reserve Sign are not in this set.

This also explains why it only errors out when you try to print it to cmd, but you can still use it in boolean comparisons. Not sure what exactly they did in python 2.X to get it functional.


Solution 2:

To print these characters you could use:

ReservedSignChar = '®';
x = ReservedSignChar.encode('utf-8');
print(x);

Post a Comment for "Printing Non-ascii Characters In Python 3"