What I want to do:
- After having declared some variables, a list of the names of those variable is defined. Then, I would like to delete the variables using their names contained in the list.
Here is a simple reproducible example :
# variables are defined
variable_a = "first elt"
variable_b = "second elt"
# for some reasons, a list of variable names is defined and filled
list_of_variables_names = ['variable_a', 'variable_b']
# then variables are to be deleted
# using the list of variable names
What I tried, which obviously, does not work
for variable in list_of_variables_names:
del variable
The above code does not delete variables, because elements of the list are name of variables (strings inside '').