kilojoules
kilojoules

Reputation: 10093

ipython function to send last command to script

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

Answers (1)

ZSH
ZSH

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

Related Questions