问题
I would love to do something like this:
rates={'r1':10, 'r2':20}
and then do some cool command (what is it???) to end up with variables in my namespace
>>>r1
10
>>>r2
20
Is this a dumb idea?
回答1:
You can just do:
globals().update(rates)
Anyway, it's usually a bad practice.
globals()
来源:https://stackoverflow.com/questions/22675221/python-create-variables-from-dictionary-entries