jupyter notebook清除输出

jupyter notebook参数化运行python 时,怕输出太多文件太大,想及时清除 notebook 的输出。
在别人代码里看到用 easydlclear_output()。调用很简单:

from easydl import clear_output

print('before')
clear_output()  # 清除输出
print('after')

查它源码:clear_output

def clear_output():
    """
    clear output for both jupyter notebook and the console
    """
    import os
    os.system('cls' if os.name == 'nt' else 'clear')
    if is_in_notebook():
        from IPython.display import clear_output as clear
        clear()
  • terminal/console 的输出调系统的 clear/cls 命令清除
  • notebook 的输出用 IPython.display.clear_output() 清除

其中 is_in_notebook() 也是 easydl 的函数,用来判断是不是在 notebook 里。
查它源码:is_in_notebook

def is_in_notebook():
    import sys
    return 'ipykernel' in sys.modules
  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值