0

2 つのリスト (CSV ファイルから読み取られる) を比較し、A にある項目と B にない項目、およびその逆を返すためのコードがあります。これが私が持っているものです:

import csv

#open CSV's and read first column with product IDs into variables pointing to lists
with open("A.csv", "rb") as f: 
    a = {row[0] if len(row) else default_value for row in csv.reader(f)}
with open("B.csv", "rb") as g: 
    b = {row[0] if len(row) else default_value for row in csv.reader(g)}


#create variables pointing to lists with unique product IDs in A and B respectively 

in_a_not_b = a-b 
in_b_not_a = b-a 

print len(in_a_not_b), " items in A missing from B", in_a_not_b
print len(in_b_not_a), " items in B missing from A", in_b_not_a


print "done!" 

このエラーが発生するまで、以前は問題なく実行されていました。

Traceback (most recent call last):
  File "C:/.../python - Comprare two lists", line 7, in <module>
    b = {row[0] if len(row) else default_value for row in csv.reader(g)}
  File "C:/.../python - Comprare two lists", line 7, in <setcomp>
    b = {row[0] if len(row) else default_value for row in csv.reader(g)}
NameError: global name 'default_value' is not defined

誰でも助けてもらえますか?ありがとう!

4

2 に答える 2