>>> class A:
    def a(self):
        print("I'm a")

>>> A.a()

Traceback (most recent call last):
  File "<pyshell#10>", line 1, in <module>
    A.a()
TypeError: unbound method a() must be called with A instance as first argument (got nothing instead)


问题解析:

因为这样定义的就是一个类方法,如果要直接用A.a(),就需要定义一个静态方法,如:

class A:
    @staticmethod
    def a():
        print ("I'm a")

A.a()


不直接用A.a()的方法:

class A:
    def a(self):
        print("I'm a")

obj = A()
obj.a()