python 类
(正确方式)
>>> class a():
def b(self):
print "ok"
>>> c = a()
>>> c.b()
ok
(错误方式)
>>> class a():
def b(self):
print "ok"
>>> a.b()
Traceback (most recent call last):
File "<pyshell#66>", line 1, in <module>
a.b()
TypeError: unbound method b() must be called with a instance as first argument (got nothing instead)
>>> class a():
def b(self):
print "ok"
>>> c = a()
>>> c.b()
ok
(错误方式)
>>> class a():
def b(self):
print "ok"
>>> a.b()
Traceback (most recent call last):
File "<pyshell#66>", line 1, in <module>
a.b()
TypeError: unbound method b() must be called with a instance as first argument (got nothing instead)
![](http://img.zemanta.com/pixy.gif?x-id=4cdfce68-f836-8a12-8345-7d3512741263)