有没有办法获得 Jupyter notebook 的整个输出历史?
答案 0 :(得分:0)
python 中有两个对象 In 和 Out 对象。 它们是这样工作的: 先写了一段代码
import math
math.sin(2) #now, replacing with math.cos(3) and running again
输出:
0.9092974268256817 #when replaced with cos, O/P: -0.4161468365471424
现在检查输入历史:
In [4]: print(In)
['', 'import math', 'math.sin(2)', 'math.cos(2)', 'print(In)']
现在检查输出历史:
In [5]: Out
Out[5]: {2: 0.9092974268256817, 3: -0.4161468365471424}
注意:当笔记本关闭并重新启动时,这不会获得历史记录。它仅在当前会话中有效。
查看此链接以获取更多解释:https://jakevdp.github.io/PythonDataScienceHandbook/01.04-input-output-history.html
答案 1 :(得分:0)
例如,你做这样的事情 - In[1]: 1+2
你得到 Out[1]: 3
。
因此,您可以在下一行执行此操作:
In[2]: print(In[1])
也用于输出
print(Out[1])
检查这个 - Output History