我刚开始学习python,最近在学习类时遇到了一个问题。请看一下代码。
class Critter(object):
"""your very own bug generator"""
total=0
def status(x):
print Critter.total
status=staticmethod(status)
def __init__(self,name):
print'a critter has been created'
self.name=name
Critter.total+=1
crit1=Critter('pooch')
crit2=Critter('Duff')
crit3=Critter('pluto')
Critter.status()
print'\nAccessing the class attributes through an object:',crit1.total
运行代码时出现此错误:
line 19, in <module>
Critter.status(Critter.total)
TypeError: unbound method status() must be called with Critter instance as first
argument(got int instance instead)
我仍然不清楚绑定/未绑定的工作原理。很抱歉初学者的问题,任何帮助将不胜感激。