gpt4 book ai didi

python - 在继续之前检查文件列表是否存在?

转载 作者:太空宇宙 更新时间:2023-11-04 08:50:34 26 4
gpt4 key购买 nike

我每天为 9 个不同的文件运行一些 pandas 代码。目前,我有一个计划任务在特定时间运行代码,但有时我们的客户端没有按时将文件上传到 SFTP,这意味着代码将失败。我想创建一个文件检查脚本。

最佳答案

import os, time

filelist = ['file1','file2','file3']

while True:
list1 = []

for file in filelist:
list1.append(os.path.isfile(file))

if all(list1):
# All elements are True. Therefore all the files exist. Run %run commands
break
else:
# At least one element is False. Therefore not all the files exist. Run FTP commands again
time.sleep(600) # wait 10 minutes before checking again

all() 检查列表中的所有元素是否都为 True。如果至少有一个元素为 False,则返回 False

关于python - 在继续之前检查文件列表是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35795452/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com