0
x = 14

variable_name = 'x'

How can I get the value of x when I only have the name of it as a string?

1 Answers1

0

You can use vars():

vars()[variable_name]

Which gives the variables of the scope it's called at (Source).

Kraigolas
  • 5,121
  • 3
  • 12
  • 37