我创建了一个代码来获取两个.txt文件,将它们进行比较并将结果导出到另一个.txt文件。下面是我的代码(抱歉有关混乱)。将结果写入.txt文件
任何想法?或者我只是一个傻子?
使用Python 3.5.2:
# Barcodes Search (V3actual)
# Import the text files, putting them into arrays/lists
with open('Barcodes1000', 'r') as f:
barcodes = {line.strip() for line in f}
with open('EANstaging1000', 'r') as f:
EAN_staging = {line.strip() for line in f}
##diff = barcodes^EAN_staging
##print (diff)
in_barcodes_but_not_in_EAN_staging = barcodes.difference(EAN_staging)
print (in_barcodes_but_not_in_EAN_staging)
# Exporting in_barcodes_but_not_in_EAN_staging to a .txt file
with open("BarcodesSearch29_06_16", "wt") as BarcodesSearch29_06_16: # Create .txt file
BarcodesSearch29_06_16.write(in_barcodes_but_not_in_EAN_staging) # Write results to the .txt file
具体问题是什么?预期的行为是什么?你需要解释发生了什么,而不只是说'任何想法?'。 –
你是否遇到特定错误? - 您也可以在代码块中设置您的帖子的格式。开始任意行的4个空格开始一个代码块 – sytech
@Rick S对于模糊的问题抱歉。结果没有出现在文本文件中,就像他们应该那样。 – minidave2014