2017-04-23 54 views
0

我想創建一個腳本,它將在每分鐘的頂部運行代碼。我正在研究調度模塊,並遇到一些奇怪的問題。Python 3調度模塊

第一個問題是導入調度運行我的腳本兩次。

import sched 
print('hello') 

輸出:

Hello 
Hello 

而且這個代碼從documentation來直:

import sched, time 
s = sched.scheduler(time.time, time.sleep) 

產生這個錯誤:

AttributeError: module 'sched' has no attribute 'scheduler' 
+2

你有沒有一個名爲sched.py的文件?這適用於python2和python3。 –

+0

嘗試了你的兩個例子,他們在我的最後工作得很好。可能要確保您的環境設置正確。 – EthanBar

+0

是的,我已經命名了文件sched.py。看來我是在自己內部導入文件。 –

回答

1

按我的意見 - 你文件是名稱爲sched.py,因此它是自己導入的,其中沒有屬性scheduler