-1

Let's say I have a simple python script math_ops.py as follows:

a = 5
b = 4
c = 7
d = a + b
e = b - c
print(d)

I run this script in the Ubuntu terminal as $ python math_ops.py, which prints the value of variable d as 9. Can I somehow get the value of variable e without rerunning the script? It is easy to get the variable values in IDE in such a scenario, but how to retrieve the variables in the terminal?

1 Answers1

0

You can't do this without somehow saving the variable to file.

If you use an interactive interpreter you can run the script in the interpreter and any global variables it creates will still be available to you when the script finishes executing. However, in this case they will still be lost when the interpreter closes.

You should just save them to file. Check out the dump/load functions in the built in json or pickle modules for easily writing/reading small amounts of data to file.