【问题标题】:"python setup.py egg_info failed with error code 1 " is displaying“python setup.py egg_info failed with error code 1”正在显示
【发布时间】:2017-11-21 06:30:16
【问题描述】:

在 Selenium Webdriver 中,我正在使用 Pycharm 中的 Python 开发,其中我使用简单的类,其中调用了两种方法分别在 Chrome 和 Safari 中打开 URL。

from selenium import webdriver


    class Automation():
        def Safari(self):
            driver = webdriver.Safari()
            driver.get('https://bizplace.theentertainerme.com')

        def Chrome(self):
            driver = webdriver.Chrome('/usr/local/bin/chromedriver')
            driver.get('https://bizplace.theentertainerme.com')

    auto = Automation
    auto.Safari(self)

现在执行后,我收到如下错误:

    auto.Safari(self)
NameError: name 'self' is not defined

我正在尝试通过命令行安装 self 包,它给我一个这样的错误:

Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/hh/bwg2n8w54cd7852cx91v21qm0000gp/T/pip-build-XVmlLB/public/setup.py", line 28, in <module>
        setup_cfg_data = read_configuration(path)
      File "/private/var/folders/hh/bwg2n8w54cd7852cx91v21qm0000gp/T/pip-build-XVmlLB/public/setup.py", line 23, in read_configuration
        val = open(val).read()
    IOError: [Errno 2] No such file or directory: './README.rst'

谁能帮帮我。

【问题讨论】:

    标签: python python-3.x selenium-webdriver pycharm


    【解决方案1】:

    不确定您为什么要尝试安装 the self package,您没有在代码中使用它,也不需要它。

    在调用您的方法时,您的问题是一个简单的错误:

    auto = Automation
    auto.Safari(self)
    

    此代码在您的课程之外,名称self 未在此处定义,您会收到您所看到的错误:

    NameError: name 'self' is not defined
    

    调用你的方法的正确方法是这样的:

    auto = Automation
    auto.Safari()
    

    由于您正在调用实例的方法,self(您调用的实际方法所属的实例)将automatically be passed as first argument

    不要走错路,但我认为你需要work your way through the Python tutorial,因为这是一个基本的错误,并且使用更复杂的代码你会遇到无数这样的问题并且不会享受你的项目。

    【讨论】:

      猜你喜欢
      • 2018-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-06
      • 1970-01-01
      相关资源
      最近更新 更多