Python透明屏幕问题跨平台

2024-04-25 14:56:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python初学者,正在开发一个交互式shell/终端。 我想通过输入以交互方式清除屏幕。 有人能帮我找出一个跨平台的解决方案吗


Tags: 终端屏幕跨平台解决方案shell初学者
1条回答
网友
1楼 · 发布于 2024-04-25 14:56:51

你可以用系统库来做。 如果您使用的是linux或mac:

system('clear')

窗口:

system('cls')

这是一个一般功能:

from os import system, name 

def clear(): 

    # for windows 
    if name == 'nt': 
        _ = system('cls') 

    # for mac and linux(here, os.name is 'posix') 
    else: 
        _ = system('clear') 

相关问题 更多 >