ipython函数将最后一个命令发送到脚本

时间:2016-07-02 02:40:24

标签: ipython

有没有办法可以将我的最后一个ipython命令发送到脚本?

所需的用法如下:

$ tail script.py
...

[1] my_command = 0
[2] %saveLastCmd script.py  # equivalent to $ echo <command> >> script.py

$ tail script.py
....
my_command = 0

[1] my_command = 1
[2] %saveLastCmd script.py  # equivalent to $ echo <command> >> script.py

$ tail script.py
....
my_command = 0
my_command = 1

1 个答案:

答案 0 :(得分:2)

# Save the contents of a cell or output to a .py file

def foo(): print('bar')
foo()

# -f forces overwrite of output file, -a appends to file

%save -f -a 'foo_in' _ih[-1]