Created
August 23, 2018 15:46
-
-
Save syrte/d02aa21933f42786f6ec960ecfff64bf to your computer and use it in GitHub Desktop.
What a useless snipet!
This file contains 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
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