Skip to content

Instantly share code, notes, and snippets.

@syrte
Created August 23, 2018 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syrte/d02aa21933f42786f6ec960ecfff64bf to your computer and use it in GitHub Desktop.
Save syrte/d02aa21933f42786f6ec960ecfff64bf to your computer and use it in GitHub Desktop.
What a useless snipet!
def import_vars(**dict_list):
"""
dict_list: namespaces to import
Examples
--------
dic1 = dict(x=1, y=1)
dic2 = dict(a=1, b=1)
exec(import_vars(dic1=dic1, dic2=dic2))
print(x, y, a, b)
"""
code = "\n".join(f"{key} = {dic}['{key}']" for dic in dict_list for key in dict_list[dic])
return code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment