I am a beginner in python. I'm not to sure how to compress a simple text file with the user's sentence. Is the easiest way to go about it by using ".compress()".I need to compress a file into a list of words from the user's input to recreate the original file. What does this mean?
and do it to compress "file.txt"'s content, creating "compressedFile.zlib":
text = open("file.txt", "rb").read() with open("compressedFile.zlib", "wb") as myFile: myFile.write(zlib.compress(text))
and do it if you need to decompress "compressedFile.zlib" later and get its content:
compressedText = open("compressedFile.zlib", "rb").read() decompressedText = zlib.decompress(compressedText)