Post: Python Task Help
01-18-2017, 07:57 PM #1
Ali
Can’t trickshot me!
(adsbygoogle = window.adsbygoogle || []).push({}); Well this is PART of a school task.

I cant seem to understand how to compress a text file. I've checked out gzip and zlib libraries, they do give good info but I cant seem to understand how to do it.

The program should be able to compress a file into a list of words and list of positions to recreate the original file.

Help pls ty
01-19-2017, 12:48 PM #2
Sparrow
Big Papi
Originally posted by Ali View Post
Well this is PART of a school task.

I cant seem to understand how to compress a text file. I've checked out gzip and zlib libraries, they do give good info but I cant seem to understand how to do it.

The program should be able to compress a file into a list of words and list of positions to recreate the original file.

Help pls ty


Something like this? You must login or register to view this content.

    import zlib, base64
text = 'STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW '
code = base64.b64encode(zlib.compress(text,9))
print code

which gives :

    eNoLDnF09lbwD3MNcvPxD1cIHhxcAE9UKaU=

Now I can copy this code to a different program to get the original program back:

    import zlib, base64
s='eNoLDnF09lbwD3MNcvPxD1cIHhxcAE9UKaU='
data = zlib.decompress(base64.b64decode(s))
print data
01-19-2017, 07:16 PM #3
Ali
Can’t trickshot me!
Originally posted by Sparrow View Post
Something like this? You must login or register to view this content.

    import zlib, base64
text = 'STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW STACK OVERFLOW '
code = base64.b64encode(zlib.compress(text,9))
print code

which gives :

    eNoLDnF09lbwD3MNcvPxD1cIHhxcAE9UKaU=

Now I can copy this code to a different program to get the original program back:

    import zlib, base64
s='eNoLDnF09lbwD3MNcvPxD1cIHhxcAE9UKaU='
data = zlib.decompress(base64.b64decode(s))
print data


Yeah but like I want to understand the code you know bro Kappa i dont understand this base64 part and b64decode.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo