【问题标题】:Can't clear python shell无法清除 python shell
【发布时间】:2020-08-11 16:47:17
【问题描述】:

我使用的是 Windows 10、Python 3.8。我正在尝试清除 shell 中的所有内容,但我使用的代码似乎不起作用。

这是我的代码:

import os
print("Erase This Text")
os.system('cls')
os.system('clear') #This is used for Linux, but I tried it just incase

【问题讨论】:

标签: python windows operating-system


【解决方案1】:

在我的带有 python 3.8 的 Windows 10 上,您的代码可以正常工作! cmdpowershell

但是你可以尝试一些解决方法,只打印空行,这会将你的光标带到屏幕下方并且数据将是空白的,因为它会传递 cmd 高度

def cls(height=100):
    [print() for _ in range(height)]

但如果你想以正确的方式解决它,也许你应该检查你的 cmd 文本编码设置。

【讨论】:

    猜你喜欢
    • 2017-06-13
    • 1970-01-01
    • 2017-11-07
    • 2020-04-25
    • 2013-07-01
    • 2020-01-08
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多