Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在运行期间停止一个while循环并返回开始?_Python_Python 3.x - Fatal编程技术网

Python 如何在运行期间停止一个while循环并返回开始?

Python 如何在运行期间停止一个while循环并返回开始?,python,python-3.x,Python,Python 3.x,我的程序每10分钟写一个文件,然后使用PIL来操作它。 但是,由于旧电脑和较慢的外部硬盘,它有时无法创建新文件。所以PIL只使用旧文件 我想写一个脚本,检查是否已经根据文件大小创建了一个新文件,如果它不是应该的大小,循环将在PIL部分之前停止,并立即从顶部重新启动程序 所以它看起来像这样: while True: #task A that saves a new file # new script to check the file size if corr

我的程序每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 

“中断并重新启动”?那不是继续吗?“中断并重新启动”是什么意思?再次转到while循环的顶部?循环中的
continue
语句将终止当前迭代,并使用下一次迭代重新启动循环。
break
语句将终止循环,并在循环外继续循环后的代码。“通过”是我不知道的声明。我想“继续”和“通过”一样