2016-07-02 4 views
1

Gibt es eine Möglichkeit, dass ich meinen letzten ipython-Befehl an ein Skript senden kann?ipython-Funktion zum Senden des letzten Befehls an das Skript

Wunsch Nutzung wäre so etwas wie:

$ 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 
+0

durch die ipython magischen Funktionen Lesen und dem Schreiben meiner Frage in Google – kilojoules

Antwort

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] 
+0

Sie den '-1' Index ändern können beliebige Zelle zu speichern, die Sie möchten . mit '% save 'foo' _ [- 1]' sollte auch die letzte Ausgabe ausgegeben werden. – zhespelt

+0

Kann ich das verwenden, um an ein auslaufendes Skript wie in meinem Beispiel anzuhängen? – kilojoules

+0

'?% Save' für das Speichern magic help doc. – zhespelt

Verwandte Themen