利用 subprocess 模块

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

Python
import subprocess as sp sp.call('cls',shell=True)
1
2
3
import subprocess as sp
sp.call('cls',shell=True)
 

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

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

For linux, you must replace cls command with clear

Python
tmp = sp.call('clear',shell=True)
1
2
3
tmp = sp.call('clear',shell=True)
 
 

利用 os 模块

Python
import os os.system('cls') # For Windows os.system('clear') # For Linux/OS X
1
2
3
4
5
import os
 
os.system('cls')  # For Windows
os.system('clear')  # For Linux/OS X
 

推荐利用快捷键

ctrl + L

Clear screen in shell 清空 shell 的输出

Clear screen in shell 清空 shell 的输出


相关文章:

  • 2022-12-23
  • 2022-01-24
  • 2021-05-21
  • 2021-05-30
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-24
  • 2022-02-10
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2021-07-18
相关资源
相似解决方案