将制表符分隔的文件转换为字典(python)(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 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更多推荐
发布评论