class a(str):
def b(self,*x,**y):
print str.decode(self,*x,**y)
b=a()
b.b('utf-8','aaa') # This prints nothing, why?
Run Code Online (Sandbox Code Playgroud)
尝试首先初始化您的字符串,具有一些值:
# classes should have capitalized names ...
class a(str):
def b(self,*x,**y):
print 'debugging: ', self, x, y
print str.decode(self, *x,**y)
if __name__ == '__main__':
b=a('aaa')
b.b('utf-8')
b=a()
b.b('utf-8')
# => output
# debugging: aaa ('utf-8',) {}
# aaa
# debugging: ('utf-8',) {}
#
Run Code Online (Sandbox Code Playgroud)