【问题标题】:How to Clear Python Output Programatically in Google Colaboratory?如何在 Google Colaboratory 中以编程方式清除 Python 输出?
【发布时间】:2018-10-11 02:46:30
【问题描述】:

这个问题是针对 Google Colaboratory 的,虽然某些解决方案可能适用于普通的 Python 解释器,但 Google Colaboratory 似乎不允许我以编程方式清除 Python 解释器输出。

我已经尝试过但不起作用的解决方案:

import os
os.system('cls')
os.system('clear')
!cls
!clear

【问题讨论】:

    标签: python google-colaboratory


    【解决方案1】:
    from google.colab import output
    
    
    
      output.clear()
    

    【讨论】:

      【解决方案2】:

      from IPython.display import clear_output clear_output()

      这对我很有用。

      【讨论】:

        【解决方案3】:

        这个 sn-p 将停止当前的 Python 运行时并重新连接到新的运行时。 (您的文件系统将保持不变。)

        import os
        os.kill(os.getpid(), 9)
        

        【讨论】:

        • 不幸的是,这不适合我的用例,它要求运行时在屏幕被清除后继续执行。
        猜你喜欢
        • 2018-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-13
        • 1970-01-01
        • 2011-07-22
        相关资源
        最近更新 更多