【问题标题】:How to clean Python´s shell? [duplicate]如何清理 Python 的外壳? [复制]
【发布时间】:2020-12-13 14:35:12
【问题描述】:

我开始学习python,当我想擦除shell中的所有结果时,我需要关闭shell,我可以用一些命令或控制键盘来做到这一点吗?

【问题讨论】:

  • 如果您指的是终端会话中的交互式 shell,您可以使用 Ctrl+d

标签: python python-3.x developer-tools


【解决方案1】:

试试这个代码: 导入操作系统

def clear():
    name = os.name

    if name == 'nt':  # windows
        os.system('cls')
    else:  # mac and linux
        os.system('clear')
        
 

【讨论】:

    【解决方案2】:

    您可以使用os.system('clear') 与操作系统对话,并要求系统运行清除命令。当然要在开头加上import os

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      • 2019-09-09
      • 2022-08-09
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多