print a
以下の例で例外が発生する理由を誰かが説明できますかa.__str__()
?
>>> class A:
... def __init__(self):
... self.t1 = "čakovec".decode("utf-8")
... self.t2 = "tg"
... def __str__(self):
... return self.t1 + self.t2
...
>>> a = A()
>>> print a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u010d' in position 0: ordinal not in range(128)
>>> a.__str__()
u'\u010dakovectg'
>>> print a.__str__()
čakovectg