python 保存函数_在ipython中保存函数定义

使用%save可以保存第1行的内容,方法是: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-使用函数func1之后,可以使用_从IPython获得以下输出:In [4]: _

Out[4]: 'def func1():\n print "Hello World"\n\n'

然后,您可以使用如下更新内容定义或重新定义%macro: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"

最后,您可以使用%save和新的%macro保存新版本的func1,如下所示:In [6]: %save func1.py new_func1_macro

The following commands were written to file `func1.py`:

def func1():

print "Hello World"

希望能澄清。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值