我试图在Ubuntu上输入文本到ots
summerizer。我正在使用python2 subprocess
库。但一直得到以下错误:python2中的子进程返回错误
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的subprocess
将文本输入到ots
库。这是否是一种方法,并从ots
快速获得摘要?请帮助我。
'''--ots'='<'+ text'使用'text'中的字符串作为文件名来读取。我不知道'ots',也许它有办法从命令行接受一个字符串。如果没有,您可以通过使用[here string](http://tldp.org/LDP/abs/html/x17837.html)将它作为命令行字符串传递,就好像它来自文件一样:''ots - -ratio = 30 <<<'+ text',但是你必须告诉'subprocess'使用'bash'而不是'sh',因为'sh'不支持这里的字符串。 –