Reputation: 10093
Is there a way I can send my last ipython command to a script?
Desired usage would be something like:
$ 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
Upvotes: 1
Views: 42
Reputation: 652
# 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]
Upvotes: 2