开发者

Tab-delimited file into dictionary (python)

I have a开发者_如何转开发 tab separated file

How can I input this file into a dictionary?


import csv

with open(filename) as file_object:
    # skip the first two lines
    file_object.next()
    file_object.next()
    list_of_dicts = list(csv.DictReader(file_object, dialect='excel-tab'))

# list_of_dicts now will contain a list of dictionaries extracted from the file


You can use the csv module with its DictReader class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜