내 코드는 다음과 같습니다파이썬 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
은? - 왜 두 번째 유채 꽃의 출력 끝에 0이 추가됩니까
os.system
? 대신 인쇄 라인의
감사합니다. @kevin 귀하의 답변은 완벽하게 잘 작동했습니다. 새로운 Python과 아직 배우기. 도와 주셔서 감사합니다! 이 재미!! – 0x2