开发者

Tab-delimited file into dictionary (python)

开发者 https://www.devze.com 2023-02-16 02:59 出处:网络
I have a开发者_如何转开发 tab separated file How can I input this file into a dictionary?import csv

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

精彩评论

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