
8

如何在不改动模块的情况下重写其中某一个关键类,且其他依赖关键类的文件能自动调用重...
source link: https://www.v2ex.com/t/789291
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

说的有点抽象,下面用 selenium 模块举个例子。
在remote/webdriver.py
文件中有下面一个类,为标题说的关键类。
class WebDriver(object):
pass
在chrome/webdriver.py
文件中,依赖上述关键类,称这个文件为依赖关键类的文件
,其内容如下。
#...
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
#...
class WebDriver(RemoteWebDriver):
pass
现在,我想重写关键类。并且,依赖关键类的文件
的文件会自动调用我重写的类,基本要求是不改动模块文件。
不知列位有没有看懂,我尽力表达了... 各位 v 友,有招嘛,不懂得但是对这个问题有兴趣的可以回一下贴,顶一下,让大佬看到?,感谢感谢~
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK