# 将列表中的图片进行上传,每张图片最多尝试三次上传,如果三次都失败,则保留原连接 for i,u in enumerate(pci_urls, start=1): for t in range(1,4): try: new_u = upload(u) continue except: if t == 3: new_u = u print(f"{u} 无法上传:{e}") url_dict[u] = new_u print(f"{i} / {len(pic_urls)}")
# 对 _files 列表中的文件一一完成替换 for file in _files: with open(file, 'r') as f: content = f.read() for k, v in url_dict.items(): content = content.replace(k, v) with open(file, 'w') as f: f.write(content) print("完成替换:", file)