我正在遍历文件位置的DataFrame。如果我找到了我想要的文件,那么我会尝试解压缩它,然后尝试重命名它。如果失败,那么我想继续到数据帧的下一行。问题是如果我打电话给"继续"然后,它跳回到前一个for循环,然后我的程序挂起,而不是跳回到主循环。有没有办法指定哪个for循环可以在出现错误时回退?
这是我的伪代码:
for index, row in df.iterrows(): #if something fails I want to go back here
#get the file location
for file in location: #"continue" is taking me back to here which I don't want
#search for file
if file found:
file_found = True
if not file_found:
continue
else:
file_found = False
try:
#unzip file
except:
#could not unzip
continue
try:
#rename unzipped file
except:
try:
#try renaming a different way
except:
#could not rename file
continue