2017-11-21 7 views
-1

Selenium Webdriver에서 Pycharm에서 Python으로 작업하고 있는데, Chrome과 Safari에서 각각 URL 열기를 위해 두 개의 메소드가 호출되는 간단한 클래스를 사용하고 있습니다."Python setup.py egg_info가 오류 코드 1로 실패했습니다."

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) 

이제 실행 한 후,이 같은 오류가 점점 오전 :

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' 
: 나는 명령 줄을 통해 자체 패키지를 설치하려고

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

, 그 이렇게 나에게 오류를 던지고

나를 도와 줄 수있는 사람이 있습니까?

답변

0

the self package을 설치하려고하는 이유가 확실하지 않으며 코드에서 사용하지 않고 있으므로 필요하지 않습니다.

auto = Automation 
auto.Safari(self) 

이 코드는 이름 self 여기에 정의되지 않은, 클래스 외부에, 당신은 당신이보고있는 오류 얻을 :

당신의 메서드를 호출 할 때

문제는 여기에 간단한 실수를하다

NameError: name 'self' is not defined 

이 될 것이다 당신의 메소드를 호출하는 올바른 방법 :

auto = Automation 
auto.Safari() 

S 인스턴스의 메서드를 호출하는 경우 self (호출 한 실제 메서드가 속한 인스턴스)은 automatically be passed as first argument이됩니다.

잘못된 길을 택하지 말고 work your way through the Python tutorial이 필요하다고 생각합니다. 다소 기본적인 실수이므로 더 복잡한 코드를 사용하면 이처럼 수많은 문제에 부딪 히며 작업을 즐기지 않을 것입니다. 귀하의 프로젝트.