-3

This is my problem:

I want to make a input that will run the name of the variable that is input.

var = "working!"
cmd = input(":")
#I want it so that the user inputs "var", the var variable ("working!") is printed.
#But if I put the print like it is below, it will print a string of what is input. So, it will print "var".
print(cmd)

Essentially, I want something that turns the input string into a variable name, so I can call said variable.

MSeifert
  • 145,886
  • 38
  • 333
  • 352
SamtheMan
  • 111
  • 3

1 Answers1

-6

You need to use the eval() function:

var = "working!"
print(eval("var"))
Mike
  • 632
  • 2
  • 7
  • 17
  • 1
    This is generally considered dangerous, and it's unnecessary as it can be done with a dictionary, or if access to variables is paramount, with `globals`, without compromising your code. – Izaak van Dongen Aug 27 '17 at 18:01