def get_FolderIdxlsx(x, rightstr, saveName): path = "1/GCMA/GPD_GDSC/Study/" + x + "/2. Data Management/23. Study Metrics Report/fileUpload/" + rightstr id = FolderId.get_FolderId(path) print(path + "====" + str(id)) if id != 0: rdf = FolderList.get_all_file_info(id, None) if rdf.empty: print(str(id)+"下无文件") else: val = rdf[['FileName', 'FileId', 'FileCreateTime', 'FileModifyTime']] # 排序取最新 val = val[val['FileName'].str.contains(".xlsx")] val['date'] = pd.to_datetime(val['FileName'].str[-13:-5]) rdf = val.sort_values('date', ascending=False) downid = rdf.iloc[0][1] print(str(downid)+"下载") # 下载 region = Download_info.get_file_info(downid) # print(region) Download_all.get_file(downid, region, "data/xlsx/" + x + "$" + saveName) else: print("路径拼接异常") 下载异常直接跳过
时间: 2024-04-12 12:28:20 浏览: 149
Delphi 字符串截取函数
你可以使用 `try-except` 块来捕获下载过程中的异常,并在异常发生时跳过下载并继续执行下一个循环。以下是一个示例代码:
```python
def get_FolderIdxlsx(x, rightstr, saveName):
path = "1/GCMA/GPD_GDSC/Study/" + x + "/2. Data Management/23. Study Metrics Report/fileUpload/" + rightstr
id = FolderId.get_FolderId(path)
print(path + "====" + str(id))
if id != 0:
rdf = FolderList.get_all_file_info(id, None)
if rdf.empty:
print(str(id) + "下无文件")
else:
val = rdf[['FileName', 'FileId', 'FileCreateTime', 'FileModifyTime']]
# 排序取最新
val = val[val['FileName'].str.contains(".xlsx")]
val['date'] = pd.to_datetime(val['FileName'].str[-13:-5])
rdf = val.sort_values('date', ascending=False)
downid = rdf.iloc[0][1]
print(str(downid) + "下载")
try:
# 下载
region = Download_info.get_file_info(downid)
# print(region)
Download_all.get_file(downid, region, "data/xlsx/" + x + "$" + saveName)
except Exception as e:
print("下载异常:" + str(e))
pass # 异常发生时跳过下载并继续下一个循环
else:
print("路径拼接异常")
```
在上面的代码中,使用 `try-except` 块来捕获 `Download_all.get_file` 方法中的异常。当异常发生时,会打印出异常信息,并使用 `pass` 语句跳过下载并继续下一个循环。这样就能实现下载异常时直接跳过并继续下一个的需求。
阅读全文