ipython如何执行多行历史记录

2024-06-25 22:57:45 发布

您现在位置:Python中文网/ 问答频道 /正文

在伊普顿,我们可以使用

_ih[32:39] 

显示32到39之间的历史线。如何直接执行这些历史记录行?


Tags: 历史记录历史ih
3条回答

我使用列表符号:

exec In[34:36]

此外,如果使用edit函数编辑块,则Out列表中会包含您的代码,因此:

exec Out[35]

我最喜欢的是:

edit In[34:38]

因为我是个笨手笨脚的懒汉,第一次尝试就很难成功。

您可以使用%recall执行以前会话中的代码。请参阅%recall文档here

#Execute all code from previous session.
%recall ~1/

#Execute all code from two sessions previous the current session.
%recall ~2/

#Execute lines 1 to 5 from previous session.
%recall ~1/1-5

在最新版本的iPython上,您可以使用重新运行的magic comand:

%rerun 32:39

关于该命令的文档:http://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-rerun

相关问题 更多 >