1

我正在尝试将文本输入到otsUbuntu 上的summerizer。我正在使用 python2subprocess库。但一直收到以下错误:

text = "the shards that cut me the deepest were the ones that intended to cut , obama to melania trump as first lady 's largest public appearance since the 2016 election - speaking in front of more than 8,000 people at the women 's foundation of colorado 's 30th anniversary celebration - and she touched on personal attacks that she faced again and again"
>>> sum = subprocess.check_output('ots --ratio=30 <' + text)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/subprocess.py", line 567, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 36] File name too long

即使我已经读过ots从文件或stdin. 因此,我尝试将输入输入为:

sum = subprocess.check_output(['echo',text,'> stdin'])

但得到以下输出:

"the shards that cut me the deepest were the ones that intended to cut , obama to melania trump as first lady 's largest public appearance since the 2016 election - speaking in front of more than 8,000 people at the women 's foundation of colorado 's 30th anniversary celebration - and she touched on personal attacks that she faced again and again > stdin\n"

但这不是我想要达到的目标。我只想使用python将文本输入到ots库中。subprocess有没有办法做到这一点并ots更快地获得摘要?请帮助我。

4

1 回答 1

0

我相信您需要|管道操作员。

sum = subprocess.check_output('echo {} | ots --ratio=30'.format(text), shell=True)

bash 中的<符号用于从另一个流中获取输入。

于 2017-07-27T09:55:02.783 回答