Python Essential Reference 4th ed を読んでいます。次のコードの問題を修正する方法がわかりません
class Account(object):
num_accounts = 0
def __init__(self, name, balance):
self.name = name
self.balance = balance
Account.num_accounts += 1
def __del__(self):
Account.num_accounts -= 1
def deposit(self, amt):
self.balance += amt
def withdraw(self, amt):
self.balance -= amt
def inquire(self):
return self.balance
class EvilAccount(Account):
def inquire(self):
if random.randint(0,4) == 1:
return self.balance * 1.1
else:
return self.balance
ea = EvilAccount('Joe',400)
私の理解が正しければ、プログラムの終了時に ea オブジェクトがスコープ外になり、継承された__del__
関数を呼び出す必要がありますね。を受け取り'NoneType' object has no attribute num_accounts
ます__del__
。__init__
関数の前に文句を言わないのはなぜですか?