Wydruk Pythona nie używa __repr__, __unicode__ ani __str__ dla podklasy Unicode?

Wydruk Pythona nie jest używany__repr__, __unicode__ lub__str__ dla mojej podklasy Unicode podczas drukowania. Jakieś wskazówki co do tego, co robię źle?

Oto mój kod:

Korzystanie z Pythona 2.5.2 (r252: 60911, 13 października 2009 r., 14:11:59)

>>> class MyUni(unicode):
...     def __repr__(self):
...         return "__repr__"
...     def __unicode__(self):
...         return unicode("__unicode__")
...     def __str__(self):
...         return str("__str__")
...      
>>> s = MyUni("HI")
>>> s
'__repr__'
>>> print s
'HI'

Nie jestem pewien, czy jest to dokładne przybliżenie powyższego, ale tylko dla porównania:

>>> class MyUni(object):
...     def __new__(cls, s):
...         return super(MyUni, cls).__new__(cls)
...     def __repr__(self):
...         return "__repr__"
...     def __unicode__(self):
...         return unicode("__unicode__")
...     def __str__(self):
...         return str("__str__")
...
>>> s = MyUni("HI")
>>> s
'__repr__'
>>> print s
'__str__'

[EDYTOWANY ...] Brzmi jak najlepszy sposób na uzyskanie obiektu łańcuchowego, który jest instancją (instancja, łańcuch bazowy) i oferuje kontrolę nad wartościami zwracanymi przez unicode, a z repr jest unicode ...

>>> class UserUnicode(str):
...     def __repr__(self):
...         return "u'%s'" % super(UserUnicode, self).__str__()
...     def __str__(self):
...         return super(UserUnicode, self).__str__()
...     def __unicode__(self):
...         return unicode(super(UserUnicode, self).__str__())
...
>>> s = UserUnicode("HI")
>>> s
u'HI'
>>> print s
'HI'
>>> len(s)
2

The_str_ i_repr_ powyżej nie dodawaj niczego do tego przykładu, ale chodzi o wyraźne przedstawienie wzoru, który w razie potrzeby zostanie rozszerzony.

Aby udowodnić, że ten wzór zapewnia kontrolę:

>>> class UserUnicode(str):
...     def __repr__(self):
...         return "u'%s'" % "__repr__"
...     def __str__(self):
...         return "__str__"
...     def __unicode__(self):
...         return unicode("__unicode__")
... 
>>> s = UserUnicode("HI")
>>> s
u'__repr__'
>>> print s
'__str__'

Myśli?

questionAnswers(2)

yourAnswerToTheQuestion