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

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -