python create variables from dictionary entries

坚强是说给别人听的谎言 提交于 2019-12-25 02:38:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!