Code is for Python 2 which is dead💀
If change code and run with Python 3.9.
You can easy change later if need string.
If change code and run with Python 3.9.
import zlib MESSAGE = b"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))
Output:original: b'life of brian'
compressed message: b'x\x9c\xcb\xc9LKU\xc8OSH*\xcaL\xcc\x03\x00!\x08\x04\xc2'
decompressed message: b'life of brian'
So it need to be bytes
in and it give bytes
out.You can easy change later if need string.
>>> decompressed_message b'life of brian' >>> decompressed_message.decode() 'life of brian' # Other way around >>> s = 'life of brian' >>> s 'life of brian' >>> s.encode() b'life of brian'