请问如何调用类中定义的无参的方法?是不是这样的方法本来就不能调用?
[color=blue]# 在类中定义一个无参的方法 method()[/color]
[code="python"]
class clazz:
def method():
print m
[/code]
[color=blue]直接调用[/color]
[code="python"]
clazz.method()
Traceback (most recent call last):
File "", line 1, in
clazz.method()
TypeError: unbound method method() must be called with clazz instance as first argument (got nothing instead)
[/code]
[color=blue]先实例化,再调用[/color]
[code="python"]
c = clazz()
c.method()
Traceback (most recent call last):
File "", line 1, in
c.method()
TypeError: method() takes no arguments (1 given)
[/code]
[color=blue]这样也不行[/color]
[code="python"]
clazz.method(c)
Traceback (most recent call last):
File "", line 1, in
clazz.method(c)
TypeError: method() takes no arguments (1 given)
[/code]