Creating or assigning variables from a dictionary in Python

后端 未结 7 1620
一生所求
一生所求 2020-12-06 10:05

I tried to ask a question normally once in here but nobody understands what I want to ask. So I\'ve found example in PHP.

// $_POST = array(\'address\' =>         


        
相关标签:
7条回答
  • 2020-12-06 11:06

    You can use the locals() function to access the local symbol table and update that table:

    >>> mydict = {'raw': 'data', 'code': 500}
    >>> locals().update(mydict)
    >>> raw
    'data'
    >>> code
    500
    

    Modifying the symbol table that way is quite unusual, though, and probably not the way to go. Maybe you need to change your design so you can use the mydict dictionary instead of actual variables.

    0 讨论(0)
提交回复
热议问题