csv
入力属性がそのファイルのパスになる関数で、ファイルから辞書にレコードを追加するにはどうすればよいcsv
ですか?
この未完成の関数を手伝ってください:
def csv_file (p):
dictionary={}
file=csv.reader(p)
for rows in file:
dictionary......(rows)
return dictionary
最初にファイルを開く必要があります。
def csv_file(p):
dictionary = {}
with open(p, "rb") as infile: # Assuming Python 2
file = csv.reader(infile) # Possibly DictReader might be more suitable,
for row in file: # but that...
dictionary......(row) # depends on what you want to do.
return dictionary