【发布时间】:2013-11-22 00:47:29
【问题描述】:
class Bil(object):
def __init__(self, tankVol, aktVol=0):
self.tankVolym = tankVol
self.aktuellVolym = aktVol
def tanka(self, liter=5):
self.aktuellVolym = self.aktuellVolym + liter
over = self.aktuellVolym - self.tankVolym
if over > 0 :
self.aktuellVolym = self.tankVolym
else:
over = 0
return over
print(Bil.tanka(80))
print(Bil.aktuellVolym)
为什么它不起作用?
AttributeError:
"int" object as no attribute "aktuellVolym"
【问题讨论】:
-
Bil 是一个类。您将需要该类的一个实例 -> foobar = Bil(20)。然后你就可以使用 foobar.aktuellVolym。
标签: python class object python-3.x attributes