encode - Compressing and Encoding the contents of a file in python -


i trying compress , encode contents of file in python using zlib.compress() , encode('base64') follows:

teststr = zlib.compress("/root/scriptss/test.sh").encode('base64') print teststr 

when decompress , decode follows,

revstr = zlib.decompress(teststr.decode('base64')) print revstr 

i string /root/scriptss/test.sh output , not contents of file. have gone wrong?

you need read file:

with open("/root/scriptss/test.sh") inputfile:     teststr = zlib.compress(inputfile.read()).encode('base64')     print teststr 

zlib.compress() takes string compress, not filename.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -