Reputation: 161
I'm attempting to read the following data from a separate .py file in a different directory, specifically: "assets.ovs.screen0".
Show here is the contents of assets.ovs.screen0.placement:
selection_Size = [600,110]
selection_Loc = [1500-600,208]
selection_Mov = [0,115]
At the base of the tree is a file, test.py, currently reading:
import assets.ovs.screen0.placement as placement
requiredVar = "select_"
print placement.select_Size
print eval("placement."+ requiredVar)
Assuming there is a safer/easier way of doing this, what would it be?
Upvotes: 0
Views: 27
Reputation: 16940
Can i try this way:
param = ["selection_Size", "selection_Loc", "selection_Mov", "error"]
for par in param:
print par, placement.__dict__.get(par, None)
# this should work too
# print par, getattr(placement, par, None)
Output:
selection_Size [600, 110]
selection_Loc [900, 208]
selection_Mov [0, 115]
error None
Upvotes: 2