我的代碼是: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