看板 Python 關於我們 聯絡資訊
大家好,我在一個爬蟲framework中,建立了兩個.py檔案 第一個檔案中有一個class SeleniumDriver 第二個檔案中有一個class LoginPage LoginPage繼承SeleniumDriver 在SeleniumDriver中 def __init__(self,driver): self.driver = driver 在LoginPage中 def __init__(self,driver): super().init__(driver) self.driver = driver 在SeleniumDriver中,有很多使用self.driver的function ex. self.driver.find_element() 如果我沒有在LoginPage的__init__()中用super() ,會調用不到SeleniumDriver中的方法嗎? 為什麼呢? 謝謝 PS. code class SeleniumDriver ==> https://goo.gl/A3n4jR class LoginPage ==> https://goo.gl/NJFw1N selenium老師的解釋(看不懂) : We are using it to initialize the driver instance in the parent class│ If the parent class does not know about the driver instance, you will be able to call the methods from the parent class but they will give an exception because they do not know about driver methods│ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.141.87.71 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1514280761.A.1DB.html
s860134: __init__你下面那個打錯了 12/26 21:15
s860134: 另外你都看到 SeleniumDriver 沒做啥事情,不去引用沒差 12/26 21:15
s860134: 你會在意的是哪天 SeleniumDriver __init__ 做了甚麼事 12/26 21:16
s860134: LoginPage 是不是要一起改 12/26 21:16
jamesxxx1997: 所以其實根本就不用加上super()XD 12/26 22:20
jamesxxx1997: 謝謝S大大 12/26 22:21
uranusjr: 我的嗎啊這用繼承寫是老師教你的嗎 12/26 23:55
jamesxxx1997: u大,對的 12/27 00:37
jamesxxx1997: 這是一個selenium webdriver的framework 12/27 00:38