Created
May 6, 2011 21:18
-
-
Save MichaelBlume/959800 to your computer and use it in GitHub Desktop.
Localdict -- reduce your typing by half when constructing a dictionary literal from objects in the local context.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Localdict -- reduce your typing by half when constructing a dictionary | |
literal from objects in the local context. | |
params = {'foo': foo, 'bar': bar, 'baz': baz} | |
can be replaced ith | |
params = localdict('foo', 'bar', 'baz') | |
''' | |
import inspect | |
def localdict(*args): | |
one_up_locals = inspect.stack()[1][0].f_locals | |
return dict([(k, one_up_locals[k]) for k in args]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment