Ipython% magic store not working

I am trying to make my ipython alias be persistent, and according to the docs, the magic store% function stores this function. But this does not work for me.

wim@SDFA100461C:/tmp$ echo 'print("hello world!")' > test.py
wim@SDFA100461C:/tmp$ ipython
In [1]: alias potato python /tmp/test.py

In [2]: potato
hello world!

In [3]: %store potato
Alias stored: potato (python /tmp/test.py)

In [4]: 
Do you really want to exit ([y]/n)? 
wim@SDFA100461C:/tmp$ ipython
In [1]: potato
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-e561f9248d75> in <module>()
----> 1 potato

NameError: name 'potato' is not defined

I'm on IPython 1.1.0 / Python 2.7.5 +

+4
source share
2 answers

You need to run %store -rto retrieve stored variables (and aliases).

Of course, you can add this to your ipython script run.

+8
source

You can also restore in a regular script, for example, if your IDE (Spyder) does not support the file ipython_config.py:

from IPython import get_ipython
ipython = get_ipython()
ipython.magic("store -r")

( , "" Spyder IPython. , .)

+1

All Articles