【发布时间】:2020-02-05 18:31:30
【问题描述】:
我有这个代码
elif device_type == "7":
print("\n")
print("************************************")
print("***** *****")
print("***** Comparision Checker *****")
print("***** Of Two Configs *****")
print("************************************")
print("\n")
print('\nWARNING: Discrepancies found:')
def open_file_and_return_list(file_path):
list = []
with open(file_path, 'r') as f:
line = f.readline()
while line:
list.append(line)
line = f.readline()
return list
def clean_new_line(list):
for i in range(len(list)):
if "\n" in list[i]:
list[i] = list[i].replace("\n", "")
return list
if __name__ == "__main__":
list1 = open_file_and_return_list(r"new.txt")
list2 = open_file_and_return_list(r"standard.txt")
maxl = max(len(list1), len(list2))
list1 += [''] * (maxl - len(list1))
list2 += [''] * (maxl - len(list2))
diff = []
diff_file = input("\nINFO: Select what to name the difference(s) : ")
open(diff_file, 'w').close()
for iline, (l1, l2) in enumerate(zip(list1, list2)):
if l1 != l2:
print(iline, l1, l2)
print(iline, l1, l2, file=open(diff_file, 'a'))
当我使用选项 7 时,我显然会收到此错误。
信息:选择测试:7 Traceback(最近一次调用最后一次):
文件“C:/Users/a/a/a/pre-post-check-LATEST.py”,第 866 行,在
list1 = open_file_and_return_list(r"new.txt") ***** ***** 文件“C:/Users/a/a/a/pre-post-check-LATEST.py”,第 850 行,在 open_file_and_return_list ***** 比较检查器 ***** ***** 两个配置 *****
我该如何解决这个问题,或者显然我的逻辑不正确,我该如何解决我的逻辑? 谢谢
【问题讨论】:
-
elif必须遵循if声明。 tutorialspoint.com/python/python_if_else.htm。你可能只想要if。 -
该错误消息似乎不包含实际错误。你确定这是全部信息吗?