Python打印没有使用__repr__,__unicode__或__str__打印时我的unicode子类.关于我做错了什么的线索?
这是我的代码:
使用Python 2.5.2(r252:60911,2009年10月13日,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'
Run Code Online (Sandbox Code Playgroud)
我不确定这是否是上述的准确近似值,只是为了比较:
>>> 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 …Run Code Online (Sandbox Code Playgroud)