Let's say I have a gzipped file, but my script only takes in an uncompressed file.
Without modifying the script to take in a compressed file, could I uncompress the file on the fly with bash?
For example:
python ../scripts/myscript.py --in (gunzip compressed_file.txt.gz)
You can use a process substitution, as long as the Python script doesn't try to seek backwards in the file:
Python receives a file name as an argument; the name just doesn't refer to a simple file on disk. It can only be opened in read-only mode, and attempts to use the
seekmethod will fail.If you were using
zshinstead ofbash, you could useand Python would receive the name of an actual (temporary) file that could be used like any other file. Said file would be deleted by the shell after
pythonexits, though.