Question: __repr__ can't print unicode right
Walter Wong
h2owong at yahoo.com
Tue Nov 21 21:36:13 EST 2000
I am trying to write a class that handle Chinese big5 code. But find
some problem in printing the __repr__ value.
>>> class chinese:
def __init__(self, value):
self.data = value
def __repr__(self):
return `self.data`
Let's said I assign a chinese word to the class' instance.
x.data and x should return the same unicode like this
>>> x = chinese('你')
>>> x.data
'\247A'
>>> x
'\247A'
But when I try to print the two. They come out differently.
>>> print x.data
你
>>> print x
'\247A'
Is there any way that I can print the chinese word right?
>>> print x
你
Thanks and regard
Walter Wong
More information about the Python-list
mailing list