在外壳中清除屏幕 [英] Clear screen in shell

查看:31
本文介绍了在外壳中清除屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是一个简单的问题:
你如何清除shell中的屏幕?我见过这样的方法:

Just a quick question:
How do you clear the screen in shell? I've seen ways like:

import os
os.system('cls')

这只是打开windows cmd,清除屏幕并关闭但是我想要清除 shell 窗口
(PS:我不知道这有帮助,但我使用的是 Python 3.3.2 版)
谢谢:)

This just opens the windows cmd, clears the screen and closes but I want the shell window to be cleared
(PS: I don't know this helps, but I'm using version 3.3.2 of Python)
Thank you :)

推荐答案

对于 macOS/OS X,您可以使用 subprocess 模块并从 shell 调用 'cls':

For macOS/OS X, you can use the subprocess module and call 'cls' from the shell:

import subprocess as sp
sp.call('cls', shell=True)

要防止0"显示在窗口顶部,请将第二行替换为:

To prevent '0' from showing on top of the window, replace the 2nd line with:

tmp = sp.call('cls', shell=True)

对于 Linux,您必须将 cls 命令替换为 clear

For Linux, you must replace cls command with clear

tmp = sp.call('clear', shell=True)

这篇关于在外壳中清除屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆