Reputation: 558
I have a python script which prints many lines to the stdout using the command:
sys.stdout.write(...)
I would like to write those strings serially to a gzipped file, meaning at the end what should be executed is:
python3 myscript.py | gzip > data_out.txt
Upvotes: 0
Views: 52
Reputation: 592
I would have added text in some variable while i am throwing on console and finally would have created gzip file out of that temp variable, would have used gzip package:
import gzip
with gzip.open('data_out.gz', 'wt') as f:
f.write(temp_str) #assuming temp_str contains text
Upvotes: 1