Python 我如何从方法列表中判断哪些方法是在该类中定义的,哪些是继承的?
我如何从方法列表中判断哪些方法是在该类中定义的,哪些是继承的?我有一个银行模块,它有两个类,BankAccount和Transactions。Transactions从BankAccount继承Python 我如何从方法列表中判断哪些方法是在该类中定义的,哪些是继承的?,python,inheritance,Python,Inheritance,我如何从方法列表中判断哪些方法是在该类中定义的,哪些是继承的?我有一个银行模块,它有两个类,BankAccount和Transactions。Transactions从BankAccount继承 >>> dir(bank.BankAccount) [ 'chk', 'interest'] >>> dir(bank.Transcations) [ 'chk', 'deposit', 'interest', 'withdraw'] 如何检查“chk”和“in
>>> dir(bank.BankAccount)
[ 'chk', 'interest']
>>> dir(bank.Transcations)
[ 'chk', 'deposit', 'interest', 'withdraw']
如何检查“chk”和“interest”方法是否被继承,是否可以判断继承自哪个类?您可以检查
bank.Transactions.\u dict\u.keys()
>>> class BankAccount(object):
... def deposit(self):
... pass
... def account_no(self):
... pass
...
>>> class Transaction(BankAccount):
... def withdrawal(self):
... pass
...
>>> Transaction.__dict__.keys()
['__module__', '__doc__', 'withdrawal']
>>> BankAccount.__dict__.keys()
['__module__', 'deposit', '__dict__', '__weakref__', '__doc__', 'account_no']