I have some code writing output to a file that I want zipped, but I can't figure out how I would write it to a zipped file.
subprocess.run([f"grep -i -m 1 'REMARK VINA RESULT:' ./output/{docking_type}/output_{filename} \
| awk '{{print $4}}' >> results_{rank}.txt; echo {filename} \
>> results_{rank}.txt"], shell=True)
At this point I can only see writing the output then taking that file and zipping it, but I'm hoping to combine those steps, since I am writing a very large number of files. From the gzip documentation this would be done via:
import gzip
content = b"Lots of content here"
with gzip.open('/home/joe/file.txt.gz', 'wb') as f:
f.write(content)
Am I just misunderstanding gzip? Thanks for any help!
I've tried a few variations without success so far!
Try this: