$ cat test.py
#!/usr/bin/python
import os
import sys
import subprocess
list_of_lists = []
process = subprocess.Popen(["cmd/tree-tagger-english-utf8"], stdout=subprocess.PIPE)
(output, err) = process.communicate(sys.stdin)
count = 0
for line in output.split('\n'):
# condition to skip the first 3 lines
if count<3:
count=count+1
else:
new_list = [elem for elem in line.split()]
list_of_lists.append(new_list)
exit_code = process.wait()
print list_of_lists
$
看看subprocess模块:下面是一个简单的例子。。。在
您还可以使用miotto's treetagger-python module,它为TreeTagger提供了一个非常易于使用的接口。在
只需确保定义一个新的
TREETAGGER
环境变量,以便Python模块知道在哪里可以找到TreeTagger可执行文件。其余的看起来很像:Here is a blog post I made detailing installation and testing,如果您需要进一步的说明。在
相关问题 更多 >
编程相关推荐