使用%run让Python代码更清爽(use %run to run other Python file in present code.)

在jupyter notebook中写Python代码,发现代码太长了,各种函数和包的定义.
因此为了让代码看着清爽点,可以将其中的一些部分放在桶目录的新建 .py 文件里,
通过 %run xx.py调用该文件,同时为了使用主文件的变量,增加 -i,即 %run -i xx.py。
这样让整个代码变得清爽。

%run xx.py  ##需要重新引入包,重新定义变量

%run -i xx.py ##共享包,变量定义

·

翻译/English

I found my jupyter nootbook has a long Python code. I found we could seperate some code block into other python file and use %run command to use them. We could also choose if we want the code in these files share some varities and imported packages.

·

Built-in magic commands
How to execute a * .PY file from a * .IPYNB file on the Jupyter notebook?

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值