【发布时间】:2015-02-16 15:12:05
【问题描述】:
我正在研究 python oop 样式。我似乎__init__的构造方法如下。我以前没见过这种风格。为什么要像这些东西一样使用双重__init__ 方法?
前-
class MinimumBalanceAccount(BankAccount):
def __init__(self, minimum_balance):
BankAccount.__init__(self)
self.minimum_balance = minimum_balance
def withdraw(self, amount):
if self.balance - amount < self.minimum_balance:
print 'Sorry, minimum balance must be maintained.'
else:
BankAccount.withdraw(self, amount)
【问题讨论】:
-
这只是Understanding Python super() with __init__() methods 的伪装。但不完全是重复的,因为如果代码没有说
super(...).__init__()会发生什么并不明显。
标签: python oop inheritance super