에러

AttributeError: 'function' object has no attribute 'every'

integerJI 2020. 9. 24. 23:14

python에서 Schedule를 테스트 하며 나온 에러입니다.

 

에러가 나온 코드

from schedule import * 
import schedule
import time
 
def schedule():
    print("I'm working...")

schedule.every(1).second.do(schedule)

while True:
    schedule.run_pending()
    time.sleep(1)

 

에러 전문

Traceback (most recent call last):
  File "schedule.py", line 1, in <module>
    from schedule import *
  File "C:\Users\kas23\Desktop\Project\algorithm\python\schedule.py", line 10, in <module>
    schedule.every(1).second.do(schedule)
AttributeError: 'function' object has no attribute 'every'

 

pip를 통해 Schedule를 설치해도 발생 하였으며

 

해당 에러의 원인은 간단합니다.

 

함수의 이름과 파일의 이름이 schedule이기 때문..

 

참고 : github.com/dbader/schedule/issues/37

 

 

함수의 이름으로 모듈 이름을 짓는 것은 어리석은 일입니다..

 

수정 소스

 

from schedule import * 
import schedule
import time
 
def job():
    print("I'm working...")

schedule.every(1).second.do(job)

while True:
    schedule.run_pending()
    time.sleep(1)