2017-01-22 34 views
0

後,這是我的代碼:回溯累積只Keyboardinterrutps

import autopy 
import time 
import math 
width, height = 400, 400 
a, b = 200, 200 
r = 150 
def drawCicle(): 
    for x in range(0, 3): 
     for angle in range(0, 360, 1): 
      x = r * math.sin(math.radians(angle)) + a 
      y = r * math.cos(math.radians(angle)) + b 
      autopy.mouse.move(int(x),int(y)) 
      time.sleep(0.002) 
def mouseMove(): 
    counter = 0 
    while counter < 4: 
     drawCicle() 
     counter += 1 
    else: 
     print('Drawing ' + str(counter) + ' circles') 
     print('moving once more in 10 seconds...') 
     counter = 0 
     time.sleep(10) 
     mouseMove() 

if __name__ == "__main__": 
    mouseMove() 

奇怪的是,該代碼運行得很好。我打破我的環帶KeyboardInterrupt後只得到回溯,從各個線圈跑這樣的溢出積累回溯:

Traceback (most recent call last): 
    File "test.py", line 27, in <module> 
    mouseMove() 
    File "test.py", line 24, in mouseMove 
    mouseMove() 
    File "test.py", line 24, in mouseMove 
    mouseMove() 
    File "test.py", line 24, in mouseMove 
    mouseMove() 
    File "test.py", line 23, in mouseMove 
    time.sleep(10) 
KeyboardInterrupt 

如果我手動破解密碼這是專門只發生,任何人都可以提供一些線索,以什麼我無視最佳做法?

+0

只需在'flush = True'中使用'print'即可立即查看打印語句。 – 2ps

回答

0

如果您想立即看到打印語句的輸出,請使用flush=True

無論輸出進行緩衝通常由文件確定的,但是如果沖洗關鍵字參數爲真時,該流被強制地刷新。當你與一個異常退出程序


def mouseMove(): 
    counter = 0 
    while counter < 4: 
     drawCicle() 
     counter += 1 
    else: 
     print('Drawing ' + str(counter) + ' circles', flush=True) 
     print('moving once more in 10 seconds...', flush=True) 
     counter = 0 
     time.sleep(10) 
     mouseMove() 

異常回溯只打印。

+0

嗯我得到一個無效的語法標誌與此'印刷('再次移動10秒...',刷新=真)'我需要在python3做到這一點? –

+0

編輯:我設置'flush = True'但是我仍然得到同樣的問題。 –