Clear terminal in Python

2018-12-31 09:03发布

Does any standard "comes with batteries" method exist to clear the terminal screen from a Python script, or do I have to go curses (the libraries, not the words)?

27条回答
何处买醉
2楼-- · 2018-12-31 09:38

If you wish to clear your terminal when you are using a python shell. Then, you can do the following to clear the screen

import os
os.system('clear')
查看更多
千与千寻千般痛.
3楼-- · 2018-12-31 09:38

In Windows you can use:

>>> import os
>>> clear = lambda: os.system('cls')
>>> clear()
查看更多
像晚风撩人
4楼-- · 2018-12-31 09:39

As for me, the most elegant variant:

import os
os.system('cls||clear')
查看更多
登录 后发表回答