如何解决使用管道与python
|import re
import subprocess
sub = subprocess.Popen([\'/home/karthik/Downloads/stanford-parser-2011-06- 08/lexparser.csh\'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr = subprocess.PIPE)
sub.stdin.write(\"i am a fan of ac milan which is the best club in the world\")
relns = []
while(True):
rel = sub.stdout.readline()
m = re.search(\"Sentence skipped\",rel)
if m != None:
print \'stop\'
sys.exit(0)
if rel == \'\\n\':
break
relns.append(rel)
print relns
sub.terminate()
所以我想要斯坦福解析器并使用lexparser.csh来解析这一行文本。但是,当我运行这段代码时,我得到的是默认文本的输出。给出的实际文本不会被解析。那么我使用管道的方式正确吗?我在很多示例中都已经看到-与命令一起使用\'-\'。为什么要使用它?因为我使用脚本的原因是脚本停在sub.stdout.readline()
解决方法
编写后,可能需要在
sub.stdin
上调用flush()
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。