外壳清晰 [英] Clear screen in 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,清除屏幕并关闭,但
我希望清除外壳窗口
(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,您可以使用子进程模块并从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屋!
查看全文