【发布时间】:2015-08-01 09:02:16
【问题描述】:
假设我有一个文本文件,grep "@" file.txt 返回:
(1) preparing corpus @ Tue Apr 28 20:19:31 CEST 2015
(1.0) selecting factors @ Tue Apr 28 20:19:31 CEST 2015
(1.2) creating vcb file /media/2tb/ccexp/phrase-mkcls-mgiza-10clusters/work.en-ru/training/corpus/en.vcb @ Tue Apr 28 20:19:31 CEST 2015
我想使用我的 python 脚本来读取输出,例如:
grep "@" file.txt | python process.py
我试过这个(process.py,但它只读取第一行:
import sys
logfile = raw_input()
print raw_input()
[出]:
(1) preparing corpus @ Tue Apr 28 20:19:31 CEST 2015
如何读取输入到 python 脚本中的所有行?
【问题讨论】:
-
for line in sys.stdin: -
谢谢@AshwiniChaudhary