I need to compress a string into some format so that I can pass it along on the command line and avoid writing it to file (which would require locking files to prevent simultaneous writes so I prefer to pass it directly). I then need to decompress the string in Python. The standard
Compress function seems like a good candidate as it indeed compresses strings into string without spaces. According to https://mathematica.stackexchange.com/a/104661/45020 I should be able to decode the string in python using
However, I cannot manage.
I tried with
import zlib data = data if isinstance(data, bytes) else data.encode('utf-8') data = base64.b64decode(data) zlib.decompress(data)
where data is the string outputted by Compress in Mathematica with the leading
1: removed as suggested in the linked post.
It decompressed without any error in python, but seems to be a meaningless string nothing like the original string that I put in. I guess that the standard Compress is no good to me in this situation?
How can I best compress a string in Mathematica in such a way that I can decompress it in Python.
Compressing using "GZIP" does not seem to work at all. I get an error
"File \!\(\"/tmp/m0000213298301.gz\"\) not found during Import"
Sorry about requiring no spaces. That was not actually important.