为什么这个Python代码什么都不打印?

zjm*_*126 0 python

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)

mik*_*iku 8

尝试首先初始化您的字符串,具有一些值:

# 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)