在Python中调用`os.system`时如何隐藏或删除0? [英] How to hide or delete the 0 when call to `os.system` in Python?
本文介绍了在Python中调用`os.system`时如何隐藏或删除0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当调用它时,如何隐藏/消除输出 0
和Python中的 os.system
命令产生的新行?
How can I hide / eliminate the output 0
and the new line that the os.system
command in Python produces when you call it?
例如:
import os
os.system('whoami')
输出:
userX
0
推荐答案
这怎么办?
from subprocess import check_output
user_name = check_output('whoami').strip()
print user_name
#out: userX
这篇关于在Python中调用`os.system`时如何隐藏或删除0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文