IrishDog
IrishDog

Reputation: 470

IPython : Running a .py file using the existing variables

Is it possible to run a .py code file using the existing variables from previous executions ? I mean to run the new .py file using the variables on memory,that is,the variables I see when I enter the who command.

Upvotes: 2

Views: 357

Answers (2)

gg349
gg349

Reputation: 22671

In Ipython, use run -i myscript.py. from the docs,

-i run the file in IPython's namespace instead of an empty one. This is useful if you are experimenting with code written in a text editor which depends on variables defined interactively.

Upvotes: 4

As long as the .py file does not define those variables, e.g. you have a "foo" variable in dir() and the .py file specifies a change to foo, then you can use the ipython magic word %load. To see the available documentation for all magic words type the following at the python prompt:

In [1]: %magic 

Upvotes: 0

Related Questions