我有一个标签分隔文件
如何将此文件输入字典?
答案 0 :(得分:3)
您可以将csv
模块与DictReader
class一起使用。
答案 1 :(得分:3)
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