我正在编写一个将两个文本文件相互比较并在另一个文本文件上输出它们的代码。到目前为止,我在第5行中始终收到“无法调用的unicode”错误。我当前的代码中缺少什么?
enter code here
import glob, os, shutil, time, string
def compare(File1,File2):
with open(File1,'r') as f:
d=set(f.readlines())
with open(File2,'r') as f:
e=set(f.readlines())
with open('C:\...\results.txt','a') as f:
for line in list(d-e):
f.write(line)
compare(r'C:\...\original_contours.txt',r'C:\...\reprojected_contours.txt')
答案 0 :(得分:0)
答案 1 :(得分:0)
将encoding='utf8'
添加到您的代码中:
with open(File1, 'r', encoding='utf8') as f:
d=set(f.readlines())
...
with open(File2, 'r', encoding='utf8') as f:
e=set(f.readlines())