【发布时间】:2015-01-12 07:40:42
【问题描述】:
我的代码是:
#!/usr/bin/python
## print linux os command output
import os
p = os.popen ('fortune | cowsay',"r")
while 1:
line = p.readline()
if not line: break
print line
retvalue = os.system ("fortune | cowsay")
print retvalue
输出是:
______________________________________
< Stay away from flying saucers today. >
--------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
______________________________________
/ Q: What happens when four WASPs find \
| themselves in the same room? A: A |
\ dinner party. /
--------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
0
我的问题是:
- 为什么在第一个
cowsay和os.popen的输出中每行后面都有一个空行? - 为什么第二个cowsay
os.system的输出末尾加了一个零?
【问题讨论】:
标签: python linux operating-system os.system