Creating or assigning variables from a dictionary in Python

后端 未结 7 1631
一生所求
一生所求 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 10:45

    Horribly late to the game, but I needed exactly this, and my solution was:

    mydict = {'raw':'data', 'code': 500}
    raw, code = [mydict.get(k) for k in ['raw','code']]
    

    That way it's explicit for reading and there's no potential clobbering of locals() (which is a magic that I'd rather avoid).

提交回复
热议问题