自学内容网 自学内容网

python交互式命令时如何清除

在交互模式中使用Python,如果要清屏,可以import os,通过os.system()来调用系统命令clear或者cls来实现清屏。

[python] view plain copy print?
>>> import os
>>> os.system('clear')

但是此时shell中的状态是:

[python] view plain copy print?
0
>>>

首行会有一个0。这个0实际上是os.system()的返回值,0是成功,非零即error code。

可以存储这个返回值,不让其打印出来:

[python] view plain copy print?
>>> import os
>>> t = os.system('clear')

这样就是真正的清屏了:

[python] view plain copy print?

原文地址:https://blog.csdn.net/hakesashou/article/details/142702305

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!