My situation is as follows: I am testing a Python script where many variables are there, and I want to print out one of the variables controlling from the command line. A toy example is (the script is called toy.py
:
import sys
a = 123
print(sys.argv[1])
From the command line I gave: python toy.py a
and the output will be a
since the a
in the command line is taken as string
by python. But the expected output is 123
, a.k.a I want Python to take the a
in the command line as a variable name.