Reading from file into Python data structure -
i have file has following format:
[ ["unique_id1", {"cc":15, "dd":30}], ["unique_id2", {"cc": 184,"dd":10}], ... ]
i want directly read file , put data in python data structure. now, i'm processing using regular expressions. there command i'm missing read directly?
this file format json you've shown us.
you can parse doing
import json out = json.load(file_object)
either or literal
out = eval(file_object.read())
or (preferred)
import ast out = ast.literal_eval(file_object.read())
Comments
Post a Comment