Skip to main content
 首页 » 编程设计

python之将制表符分隔的文件放入字典(python)

2025年05月04日18myhome

我有一个制表符分隔的文件

如何将这个文件输入字典?

请您参考如下方法:

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