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.