PHP has a function called extract() which takes an associative array as the argument and creates local variables out of the keys whose values are assigned to the key’s values. Is there a way to do this in Python? A quick google search didn’t immediately show me how. I suspect there’s a way with exec() but it’d be nice if there were some function to do it for me.
PHP has a function called extract() which takes an associative array as the argument
Share
Since it is not safe to modify the dict that locals() returns
But using exec like this is ugly. You should redesign so you don’t need to dynamically add to your local namespace
Edit: See Mike’s reservations about using repr in the comments.