is there a way to instantiate variables from iterated output in python? -
say have list my_list = ['a','b','c'] , have set of values my_values = [1,2,3]
is there way iterate through list , set values of my_list equal my_values
for in range(len(my_list)): ## operation instantiates my_list[i] variable = my_values[i] ... >>> print 1 i want without copying text of file holds program new file, inserting new lines strings need go in program. i'd skip create, rename, destroy, file operations if possible, i'm dealing pretty large sets of stuff.
this hackery shouldn't do, since globals() dict has global variables in it, can add them global dict module:
>>> my_list = ['a','b','c'] >>> my_values = [1,2,3] >>> k, v in zip(my_list, my_values): ... globals()[k] = v ... >>> 1 >>> b 2 >>> c 3 but caveat emptor, best not mix namespace variable values. don't see coming of it.
i recommend using normal dict instead store values instead of loading them global or local namespace.
Comments
Post a Comment