利用 subprocess 模块
For OS X, you can use subprocess module and call 'cls' from shell:
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:
tmp = sp.call('cls',shell=True)
1
2
|
tmp
=
sp
.
call
(
'cls'
,
shell
=
True
)
|
For linux, you must replace cls command with clear
tmp = sp.call('clear',shell=True)
1
2
3
|
tmp
=
sp
.
call
(
'clear'
,
shell
=
True
)
|
利用 os 模块
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