我試圖在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'不支持這裏的字符串。 –