简体   繁体   中英

Tab-delimited file into dictionary (python)

I have a tab separated file

How can I input this file into a dictionary?

您可以将csv模块及其DictReader类一起使用

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM