Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Localdict -- reduce your typing by half when constructing a dictionary literal from objects in the local context.
'''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
You can’t perform that action at this time.