도시에 대한 채우기 파일에 채우기 파일이 누락되었지만이 메시지가 표시 될 때 아래 오류 코드에 오류 처리를 통합하고자합니다.사전에 누락 된 값에 대한 오류 처리
형식 오류 : 기술자 'GET'는 '딕셔너리'객체를 필요로하지만, 'STR'이
import csv
import sys
import time
input_file = ('\myInput_file.csv')
output_file = ('\myOutput_file.csv')
population_file = ('\myPopulation_file.csv')
populations = {}
with open(population_file, 'r') as popfile:
for line in csv.reader(popfile):
populations[line[2]] = line[3]
with open(input_file, 'r') as infile, open(output_file, 'w', newline='') as outfile:
reader = csv.reader(infile)
writer = csv.writer(outfile, delimiter = ',')
for row in reader:
population = dict.get(populations[row[0] + row[1]], None)
new_line = [row[0]+row[1], population]
writer.writerow(new_line)
감사합니다! 너는 나에게 슬픔을 많이 덜어 준다. – DJohnson1990