小编Cla*_*diu的帖子

如何在Python中继承和扩展类属性

我在网上进行了大量研究,但是我没有找到在子类中使用新值扩展“类”属性字典的正确方法。大多数文档都是方法内部的extendend属性。

我尝试了dictionary.update()但不起作用。

这是我的示例:

class Super(object):
    dictionary = {'one':1, 'two':2}

    def __init__(self, var):
        self.var = var

    def supermethod(self):
        pass
Run Code Online (Sandbox Code Playgroud)

我扩展到:

class Subclass(Super):
    dictionary.update({"zero":0})

    def __init__(self, var):
        super(Subclass, self).__init__(var)
        self.var = var

    def submethod(self):
        pass
Run Code Online (Sandbox Code Playgroud)

如果我重写字典-可以正常工作。但是,如果我尝试扩展,它会给我AttributeError:'Subclass'对象没有属性'dictionary'

谢谢

python oop inheritance attributes dictionary

2
推荐指数
3
解决办法
3356
查看次数

Python Selenium Headless下载

我正在尝试使用硒下载文件。我已经搜索了所有内容。

Chrome中如何使用Selenium Python绑定控制文件的下载时,有人告诉它可以使用。但这对我没有用!也许我想念什么?唯一不同的是,我的页面自动启动下载了csv文件。

研究了Chrome代码后,我添加了:

        "safebrowsing_for_trusted_sources_enabled": False
Run Code Online (Sandbox Code Playgroud)

但仍然无法正常工作。

options = Options()
options.add_argument("--disable-notifications")
options.add_argument('--no-sandbox')
options.add_experimental_option("prefs", {
    "download.default_directory": "C:\\Users\\claudiu.ivanescu\\Downloads",
    "download.prompt_for_download": False,
    "download.directory_upgrade": True,
    "safebrowsing_for_trusted_sources_enabled": False
})
options.add_argument('--disable-gpu')
options.add_argument('--disable-software-rasterizer')
options.add_argument('--headless')
Run Code Online (Sandbox Code Playgroud)

感谢支持

python selenium

1
推荐指数
1
解决办法
2313
查看次数

标签 统计

python ×2

attributes ×1

dictionary ×1

inheritance ×1

oop ×1

selenium ×1