Message404853
Consider the following:
import gzip
import subprocess
with gzip.open('test.gz', 'wb') as f:
subprocess.run(['echo', 'hi'], stdout=f)
with gzip.open('test.gz', 'rb') as f:
print(f.read())
I'd expect "hi" to appear in my console. Instead, I'm getting "OSError: Not a gzipped file (b'hi')". I am attaching test.gz.
This appears for me on Debian 10 / Python 3.7 and Debian 11 / Python 3.9. I have not yet tested on other OSs and Python versions.
The reason why I expect the above to work is that the subprocess documentation states that the stdout parameter may be "an existing file object" and that on the other hand the documentation for gzip.open(...) states that it returns a file object.
Maybe this is related to #40885? |
|
Date |
User |
Action |
Args |
2021-10-23 06:13:57 | mherrmann.at | set | recipients:
+ mherrmann.at |
2021-10-23 06:13:57 | mherrmann.at | set | messageid: <1634969637.88.0.109314303688.issue45585@roundup.psfhosted.org> |
2021-10-23 06:13:57 | mherrmann.at | link | issue45585 messages |
2021-10-23 06:13:57 | mherrmann.at | create | |
|