@retry 删除文件会报异常,但不是代码问题,可以重试到运行成功
import os
from retrying import retry
import shutil
del_dir = r"C:\Users\Administrator\Desktop\school\{}\special"
@retry
def delete_dir(del_dir):
if(os.path.exists(del_dir)):
shutil.rmtree(del_dir)
print("移除文件:%s" % del_dir)
else :
print("文件不存在")
if __name__ == '__main__':
for i in range(1,3450):
try:
delete_dir(del_dir.format(i))
except:
delete_dir(del_dir.format(i))