Reputation: 11084
I am trying to do something in code, that is not working and I'm not even sure what to google for. The actual case is in python using tkinter, but here is a simple example that will make the point.
I want to create a bunch of variables so I made a list of tuples:
vars = [('var1', 'value1'), ('var2', 'value2')]
Then I want to use a syntax like this:
for item in vars:
item[0] = item[1]
This will make item[0]
equal to 'value1'
. what I want it to do is make var1
equal to 'value1'
.
I hope its clear what I'm trying to do. And I have a feeling its even trivial once I can get a hint in the right direction.
This is in python but I think the concept is more universal.
Thanks
Upvotes: 0
Views: 80
Reputation: 27802
You can use a dictionary for this purpose:
d = dict(vars)
Then you can access var1
by doing d['var1']
, which will give you value1
.
Upvotes: 4