compact() and extract() are functions in PHP I find tremendously handy. compact() takes a list of names in the symbol table and creates a hashtable with just their values. extract does the opposite. e.g.,
$foo = 'what';
$bar = 'ever';
$a = compact('foo', 'bar');
$a['foo']
# what
$a['baz'] = 'another'
extract(a)
$baz
# another
Is there a way to do the same in Python? I've looked all around and the closest I've come is this thread, which seems to frown on it.
I know about locals(), globals() and vars(), but how can I handily select just a subset of their values?
Does Python have something even better that obviates the need for this?