List to CSV(List -> CSV File)
''' 리스트 > CSV 파일 ''' import csv with open('output.csv', 'w', newline='') as file: writer = csv.writer(file) writer.writerow(['wpam', 'eggs', 'bacon', 'ham']) writer.writerow(['Hello, World!', 'eggs', 'bacon', 'ham']) writer.writerow([1, 2, 3.141592, 4])
CSV to List(CSV File -> List)
''' CSV 파일 > 리스트로 로딩 ''' import csv import pprint a_list = [] f = open('Parks.csv', 'r') reader = csv.reader(f) for row in reader: a_list.append(row) pprint.pprint(a_list) f.close() [['park.key', 'park.name', 'park.alias', 'city', 'state', 'country'], ['ALB01', 'Riverside Park', '', 'Albany', 'NY', 'US'], ['ALT01', 'Columbia Park', '', 'Altoona', 'PA', 'US'], ['ANA01', 'Angel Stadium of Anaheim'..