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
You can use the csv
module with its DictReader
class.
精彩评论