So, much to my dismay I discovered that I couldn't save a dict in a variable. However, I did discover arrays. One feature they seem to lack is a direct import from a python dictionary straight into the array using ArrayImport, as they are direct equivalents. Can this be considered for a future version? Or, if it's already possible without having to use a workaround using for loops, can someone tell me how it's done?
ArrayImport and python dicts
Posted by Mr Anonymous on Mon 14 Mar 2005 04:01 PM — 2 posts, 14,648 views.
You can try using pickle for that - just saving and loading a dictionary to/from a variable:
import pickle
#create the dictionary
d = {"1" : 1, "2" : 2, "3" : 3}
#save it in a variable
world.SetVariable("d_DICT", pickle.dumps(d))
#delete the dictionary object
del d
#load it from the variable
d = pickle.loads(world.GetVariable("d_DICT"))