【发布时间】:2020-11-22 17:35:31
【问题描述】:
我想在 python 中使用 for 循环同时遍历两个列表,因为我将使用 filecmp 比较它们的内容,如果文件内容相同则跳到下一次迭代。所以我希望两者都从索引 0 开始,这种工作语法是否有效,最好的方法是什么?
file_list = glob.glob(os.path.join(os.getcwd(), "../pythonProject", "*.json"))
duplicated_File_List = glob.glob(os.path.join(os.getcwd(), "../pythonProject/executed_Configs", "*.json"))
for file_Path, test in file_list, duplicated_File_List:
with open(file_Path) as jsonfile:
monitor_Data = json.load(jsonfile)
logging.info("Read successful")
while i < length:
if filecmp.cmp(file_Path, test, shallow=True):
i += 1
continue
其中file_Path 是file_list 中的单个文件元素,test 是duplicated_File_List 中的单个元素。
【问题讨论】:
标签: python-3.x for-loop