繁体   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