您可以使用以下方法保存行的1
内容%save
:
In [2]: %save func1.py 1
The following commands were written to file `func1.py`:
def func1():
pass
可通过以下方式获得帮助%save
:
In [2]: %save?
Type: Magic function
...
Docstring:
Save a set of lines or a macro to a given filename.
Usage:
%save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
您可以%edit
使用以下功能体:
In [3] %edit func1
done. Executing edited code...
在%edit
-ing 你的函数之后func1
,你可以使用 IPython 获得以下输出_
:
In [4]: _
Out[4]: 'def func1():\n print "Hello World"\n\n'
%macro
然后,您可以使用更新func1
内容定义或重新定义 a ,如下所示:
In [5]: %macro new_func1_macro _
Macro `new_func1_macro` created. To execute, type its name (without quotes).
=== Macro contents: ===
def func1():
print "Hello World"
最后,您可以像这样保存新版本的func1
with%save
和 new %macro
:
In [6]: %save func1.py new_func1_macro
The following commands were written to file `func1.py`:
def func1():
print "Hello World"
希望澄清。