Код: Выделить всё
import subprocess
import io
import pandas as pd
strings = ['Hello\tWorld!', 'This\tis', 'a\tTest!']
string = '\n'.join(strings)
cmd_grep = ['grep', 's']
process_grep = subprocess.Popen(cmd_grep, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
grep_stdout = process_grep.communicate(input=string.encode('utf-8'))[0].decode('utf-8')
grep_csv = io.StringIO()
for line in grep_stdout:
grep_csv.write(line)
grep_csv.seek(0)
grep_results = pd.read_csv(grep_csv,
sep='\t',
header=None,
names=['Word1', 'Word2'])
grep_csv.close()
grep_results
Код: Выделить всё
if line.startswith('This'):
grep_csv.write(line)
Подробнее здесь: https://stackoverflow.com/questions/791 ... e-together