Is it possible to convert a string to a variable?
For example:
a = b = c = 0
my_list = ["a", "b", "c"]
# any function or module to change my_list to below
my_list = [a, b, c]
Is it possible to convert a string to a variable?
For example:
a = b = c = 0
my_list = ["a", "b", "c"]
# any function or module to change my_list to below
my_list = [a, b, c]
You can use eval()
for referencing variables with their names as string as follows:
a = b = c = 0
my_list = ["a", "b", "c"]
#any function or module to change my_list to below
my_list = [eval(i) for i in my_list]
print(my_list)
Output
[0, 0, 0]