I have a .mat file in which I put data previously processed. When I perform
dict = scipy.io.loadmat('training_data.mat')
I get back a dict that is like this
{'encoders' : ......, 'decoders' : ........, 'stuff' : .....}
I want to selectively import the encoders and decoders variables into my current scope. The effect is the same as:
encoders = dict['encoders']
decoders = dict['decoders']
How do I cleanly do this without typing 10-15 lines?
You could import a dictionary
dinto the global scope usingThe same thing is impossible for local scopes, since modifying the dictionary returned by
locals()results in undefined behaviour.A slightly hacky trick you could use in this situation is to import the names into the dictionary of an on-the-fly created type:
This will at least be slightly more convenient than using
d["decoders"]etc.Alternatively, you could use
execstatements to create your variables:This could also be done selectively.