[问题] 关于class的继承在__init__()中的疑惑

楼主: jamesxxx1997 (黄~)   2017-12-26 17:32:38
大家好,我在一个爬虫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│
作者: s860134 (s860134)   2017-12-26 21:15:00
__init__你下面那个打错了另外你都看到 SeleniumDriver 没做啥事情,不去引用没差你会在意的是哪天 SeleniumDriver __init__ 做了什么事LoginPage 是不是要一起改
楼主: jamesxxx1997 (黄~)   2017-12-26 22:20:00
所以其实根本就不用加上super()XD谢谢S大大
作者: uranusjr (←這人是超級笨蛋)   2017-12-26 23:55:00
我的吗啊这用继承写是老师教你的吗
楼主: jamesxxx1997 (黄~)   2017-12-27 00:37:00
u大,对的这是一个selenium webdriver的framework

Links booklink

Contact Us: admin [ a t ] ucptt.com