목록2022/02/09 (1)
규도자 개발 블로그
[Python] csv를 dict로
[Python] csv를 dict로 가끔씩 csv로 저장된 요소들을 불러와서 dict로 써야할 때가 있다. 특히 dbeaver나 mysql workbench처럼 결과값을 간단하게 csv형태로 저장할 수 있는 어플리케이션을 다룰 때 많이 필요하더라. 먼저 코드는 아래와 같다. import csv mydict = {} with open('csv_example.csv', mode='r') as file: reader = csv.reader(file) attrs = [] result = [] for row in reader: if len(attrs) < 1: attrs = row continue temp_row_dict = dict() for key, value in zip(attr..
Python/Python
2022. 2. 9. 21:05