4

我试图让我的 ipython 别名持久化,并且根据文档,%store 魔术函数提供了此功能。但这对我不起作用。

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

我在 IPython 1.1.0 / Python 2.7.5+

4

2 回答 2

10

您需要运行%store -r以检索存储的变量(和别名)。

当然,您可以将其添加到您的 ipython 启动脚本中。

于 2014-01-06T15:09:33.300 回答
1

您还可以在常规脚本中恢复,例如,如果您的 IDE (Spyder) 不支持该ipython_config.py文件:

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

(把它放在一个在 Spyder 的 IPython 配置的启动选项卡中调用的文件中。这花了我太长时间才弄清楚。)

于 2017-11-15T02:49:55.303 回答