0

csv入力属性がそのファイルのパスになる関数で、ファイルから辞書にレコードを追加するにはどうすればよいcsvですか?

この未完成の関数を手伝ってください:

def csv_file (p):
    dictionary={}
    file=csv.reader(p)
    for rows in file:
        dictionary......(rows)
    return dictionary
4

2 に答える 2

2

最初にファイルを開く必要があります。

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
于 2013-10-25T08:40:48.300 に答える