I have a text file with a huge dictionary - and it looks like this:
{"0_3":[(80.10858194902539,-175.29917925596237,1) ],"10_10":[(50.610770881175995,-57.17018913477659,1) , (52.946319971233606,-66.9017181918025,1)].........}
It's approximately 138 mb in size, and I need to use this dictionary and access values in my python code. So, I have the following code fragment (diction.txt is the file, and I want the dictionary in my spots variable):
with open("diction.txt","r") as myfile:
data = myfile.read().replace('\n','')
exec("spots = " + data)
But, when I run this, I get a memory error, and I am not sure of this is because of the size of the file or something else, and if the size is the problem, how can I make it work?
Thanks for your help!
edit: SOLUTION:
The solution, as pointed by @DrV in the comments was to get rid of the parantheses in my file, as JSON does not recognize tuples, with the following code:
import json
with open("diction.txt","r") as myfile:
data = myfile.read().replace('\n','').replace('(','').replace(')','')
spots = json.loads(data)
And then changing the rest of my code to accommodate for the fact that I changed the format from tuples to a continuous list.