waha
waha

Reputation: 3

Is there a way to run a script on IPython interactively so that it comes afterwards what is already written?

Is there a way to run a script in iPyton with the %run myscript.py so that it will take into consideration the things I have already entered in the interactive iPython console?

Example:

In [1]: asdf = 18

In [2]:

Then if myscript.py was:

print asdf

And it was ran from iPython like this:

In [2]: %run myscript.py
18

In [3]:

Can this be done?

Upvotes: 0

Views: 311

Answers (2)

Yunzhi Ma
Yunzhi Ma

Reputation: 672

Use %logstart/%logon and %logstop/%logoff. With these controls, you will have a python_log.py file that stores your history.

Upvotes: 0

MattDMo
MattDMo

Reputation: 102852

Try using the %load magic function, available in the IPython Notebook (qtconsole or web version). It allows you to load the contents of a file into a cell, edit them if you want, then run them in the current context.

Upvotes: 2

Related Questions