'paReference'에서 내 문장을 읽는 데 문제가 있습니다.Python이 dict에 csv를 읽는 중
BrandName,LineCode,PartNo,ShortDescription,SuperStock,DropshipStock,Price,Core
Carter,5C,M3643,FILTER,0,0,14.8,0
Carter,5C,M3805,FILTER,1,0,14.8,0
Carter,5C,M4512,FILTER,2,0,14.8,0
Carter,5C,M4642,FILTER,3,0,14.8,0
Carter,5C,M60088,FILTER,4,0,14.8
Carter,5C,M60142,FILTER,6,0,14.8
Carter,5C,M60167,FILTER,7,0,14.8,0
및 abc.csv :
productcode,book_isbn,stockstatus,Price,Core,AddtoCartBtn_Replacement_Text,Availability
5CM2195,5CM2195,,,,,
5CM2846,5CM2846,,,,,
5CM3643,5CM3643,,,,,
5CM3805,5CM3805,,,,,
5CM4512,5CM4512,,,,,
5CM4642,5CM4642,,,,,
5CM60088,5CM60088,,,,,
5CM60142,5CM60142,,,,,
5CM60167,5CM60167,,,,,
내가 잘못 paRefefence의 DICT에 CSV를 읽고있다 여기
는 123.csv입니까?
c = csv.reader(open(pluginPath + "123.csv"))
d = csv.reader(open(pluginPath + "abc.csv"))
paReference ={}
for item in c:
if item[1] not in paReference:
paReference =[item[0]] = [item[1] + item[2].replace('-','')]
else:
paReference[item[1]].append(item[0])
print(item)
for item in d:
if item[0] not in paReference:
print ("Not Found! " + item[0])
else:
print ("Found! " + item[0])
Im new to python 왜 부품 번호 하나만 발견되었지만 다른 부품 번호는 찾지 못했습니다. 어떤 제안이 도움이됩니다!
'paReference = [item [0]] = [item [1] + item [2] .replace ('-', '')]'거의 당신이 원하는 것을하지 않습니다. 너는 무엇을하기를 원했는가? –
첫 번째'if' 절에서 코드를 엉망이게 할 여분의 등호가 있습니다 :'paReference = [item [0]] = [item [1] + item [2] .replace ('-' , '')] – James
키/값 쌍 컨테이너 https://docs.python.org/3.7/library/csv.html#csv에서 읽고 싶다면 사전을 만드는 대신'csv.DictReader'를 사용하십시오. DictReader – cmidi