Ich versuche, den Text auf dem ots
Summierer auf Ubuntu einzugeben. Ich benutze die python2 subprocess
Bibliothek. Aber konsequent die folgende Fehlermeldung erhalten:Subprozess in Python2 gibt Fehler
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
Auch habe ich gelesen, dass die ots
nimmt die Eingabe aus der Datei oder die stdin
. Daher habe ich versucht, Eingang zu setzen, wie:
sum = subprocess.check_output(['echo',text,'> stdin'])
Aber immer die folgende Ausgabe:
"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"
Aber es ist nicht das, was ich zu erreichen versuchen. Ich möchte nur den Text in die ots
-Bibliothek mit dem subprocess
von Python eingeben. Ist das ein Weg dies zu tun und die Zusammenfassung aus der ots
schneller zu bekommen? Bitte, hilf mir.
''ots --ratio = 30 <' + text' verwendet die Zeichenfolge in' text' als Dateiname, von dem gelesen werden soll. Ich weiß nicht "ots", vielleicht hat es eine Möglichkeit, eine Zeichenfolge von der Befehlszeile zu akzeptieren. Wenn nicht, könnten Sie eine Kommandozeilen-Zeichenfolge übergeben, als ob sie aus einer Datei kommen würde, indem Sie eine [here string] (http://tldp.org/LDP/abs/html/x17837.html) verwenden: ''ots - -ratio = 30 <<< '+ text', aber du musst 'subprocess' sagen,' bash' anstelle von 'sh' zu verwenden, da' sh' hier keine Strings unterstützt. –