我的代码是:Python的OS输出
#!/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
的输出端部的零?
谢谢@kevin你的回答非常好。新的Python和仍然学习。感谢帮助!这个很有趣!! – 0x2 2014-11-15 01:53:08