簡體   English   中英

如何在運行過程中停止 while 循環並返回開始?

[英]How to stop a while loop in the middle of its run and go back to start?

我的程序每 10 分鍾寫入一個文件,然后使用 PIL 對其進行操作。 但是,由於舊計算機和外部硬盤速度慢,有時不會創建新文件。 所以 PIL 只使用舊文件。

我想編寫一個腳本來檢查以確保根據文件大小創建了一個新文件,然后如果它不是它應該的大小,則循環在 PIL 部分之前停止,並立即從頂部重新啟動程序.

所以它看起來像這樣:

while True:
    #task A that saves a new file

      # new script to check the file size
        if correct, continue to task B
        if incorrect, break and restart

    #task B PIL image manipulation 

您正在尋找continue語句:

while True:
    #task A that saves new file

    if we_should_go_to_task_B:
        pass # This does nothing and the loop carries on
    else:
        continue # This goes back to the start of the loop

    #task B PIL image manipulation 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM