给定这堂课
class Stringy(unicode):
def __init__(self,something):
self.something = something
def __repr__(self):
return "Stringy(%s)"%repr(self.something)
def __str__(self):
return "str(%s)"%repr(self.something)
def __unicode__(self):
return "unicode(%s)"%repr(self.something)
运行以下
s = Stringy("Hello")
print s.lower() #prints "hello" !!! Why?
print s # correctly prints str('Hello')
print unicode(s) #correctly prints unicode('Hello')
print [s] #correctly prints Stringy('Hello')
print s.upper() #prints "HELLO" !!! Why?
为什么upper
// lower
etc 不触发__str__
方法?
引擎盖下不应该
unicode(self).lower()
发生类似的事情吗?
还是str(self).lower()
?