[英]Calling Superclass method in python subclass
我是 Python 的新手,我在網上閱讀了許多示例來調用超類方法子類,但沒有一個對我有用,請找到我擁有的 package 結構
F (director)
---1. __init__.py
---2.A.py
---3.B.py
內容如下
1__init__.py
is empty
2.A.py
class A:
def hi(self,name):
print ("hi",name)
3.B.py
from F.A import A
class B(A):
def testhi(self,name):
super().hi(name)
super(B,self).hi(name)
super(self).hi(name)
A.hi(self,name)
x= B()
x.testhi("python")
他們都沒有工作我總是收到錯誤消息'super' object has no attribute 'hi'
感謝@MichaelButscher,方法 hi 與 class A 處於同一級別,導致它不是 class 實例級方法。 解決這個問題解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.