Mar-13-2021, 06:57 PM
So just started playing with python, and hit a wall with zlib, just running through tutorials and came across this
I’ve tried on a different computer too
Have I done something wrong, the tutorials done tell you to convert to binary, plus if you do it puts a “b” in front of the text, also tried ‘ instead of “ as some tutorials use that instead
Bit confused
John
import zlib MESSAGE = "life of brian" compressed_message = zlib.compress(MESSAGE) decompressed_message = zlib.decompress(compressed_message) print "original:", repr(MESSAGE) print "compressed message:", repr(compressed_message) print "decompressed message:", repr(decompressed_message)Now when I run it I get this error
Error: pythonTest.py
Traceback(mostrecentcalllast):
File"Test.py",line5,in<module>
compressed_message=zlib.compress(MESSAGE)
TypeError:abytes-likeobjectisrequired,not'str'
I’ve tried a few different tutorials and all seem to give the same error, I’ve tried on python 2.7 and then installed 3.9 still the sameI’ve tried on a different computer too
Have I done something wrong, the tutorials done tell you to convert to binary, plus if you do it puts a “b” in front of the text, also tried ‘ instead of “ as some tutorials use that instead
Bit confused
John