Unicode failure

Terry Reedy tjreedy at udel.edu
Fri Dec 4 18:28:22 EST 2015


On 12/4/2015 1:07 PM, D'Arcy J.M. Cain wrote:
> I thought that going to Python 3.4 would solve my Unicode issues

Within Python itself, that should be mostly true.  As soon as you send 
text to a display, the rules of the display device take over.
>
> #! /usr/bin/python3
> # -*- coding: UTF-8 -*-

Redundant, as this is the default for 3.x

> import sys
> print(sys.getdefaultencoding())
> print(u"\N{TRADE MARK SIGN}")
>
> And here is my output.
>
> utf-8
> Traceback (most recent call last):
>    File "./g", line 5, in <module>
>      print(u"\N{TRADE MARK SIGN}")
> UnicodeEncodeError: 'ascii' codec can't encode character '\u2122' in
> position 0: ordinal not in range(128)

Tk widgets, and hence IDLE windows, will print any character from \u0000 
to \uffff without raising, even if the result is blank or ￿.  Higher 
codepoints fail, but allowing the entire BMP is better than any Windows 
codepage.

-- 
Terry Jan Reedy





More information about the Python-list mailing list