P.Escondido
P.Escondido

Reputation: 3553

How do I make variable values to be saved after running a Python script in PyCharm?

After the Python script execution I want to play with the variables which I generated during the execution.

Like, for example, one can do in RStudio, or the standard Python interpreter console.

Upvotes: 2

Views: 1444

Answers (1)

jayelm
jayelm

Reputation: 7657

I'd say the most straightforward option is to use the Python shell to simply import the file where the variable definitions are stored.

For example, foo.py would be:

a = 1
b = 2

Then in the python shell running in the same directory:

>>> import foo # or, from foo import *
>>> foo.a
1
>>> foo.b
2
>>> foo.a + foo.b
3

If you import everything, you can use any functions/classes/etc. interactively as well.

Upvotes: 3

Related Questions