python交互式命令时如何清除

737次阅读
没有评论

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?
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-06-22发表,共计383字。
新手QQ群:570568346,欢迎进群讨论 Python51学习