[英]What is the best way to keep a python loop running until stopped by the user?
在python中,保持循環運行直到被用戶停止的最佳方法如下嗎?
while not KeyboardInterrupt:
# The code I want repeated until I specify it to stop
break
我是新手,不勝感激。
摘自基思的答案
try:
while True:
do_something()
except KeyboardInterrupt:
pass
我建議您閱讀有關異常和異常處理的文章,以了解上面內容與發布的代碼之間的區別
while True:
//do your thing
這會有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.