Search the web
Sign In
New User? Sign Up
perl-python
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
gzip a file   Message List  
Reply | Forward Message #98 of 127 |
20050830

Here is a example of how to decompress a gzip file using Python.

# -*- coding: utf-8 -*-
# Python

import gzip
inF = gzip.GzipFile("/Users/t/access_log.1.gz", 'rb');
s=inF.read()
inF.close()

outF = file("/Users/t/access_log.1", 'wb');
outF.write(s)
outF.close()


Here is a example of compressing a gzip file using Python.

# -*- coding: utf-8 -*-
# Python

import gzip

inF = file("x.txt", 'rb');
s=inF.read()
inF.close()

outF = gzip.GzipFile("x.txt.gz", 'wb');
outF.write(s)
outF.close()


For more detail, see http://python.org/doc/2.4.1/lib/module-gzip.html

Perl does not come with a gzip module bundled, but one can easily call
the unix gzip with qx. (assuming you are on unix)

# perl

qx(gzip x.txt);
qx(gzip -d x.txt.gz);


Several module are available online to do compression. IO::Zlib,
PerlIO::gzip.

----------
this post is archived at:
http://xahlee.org/perl-python/gzip.html

☄



Fri Sep 2, 2005 6:16 am

p0lyglut
Offline Offline
Send Email Send Email

Forward
Message #98 of 127 |
Expand Messages Author Sort by Date

20050830 Here is a example of how to decompress a gzip file using Python. # -*- coding: utf-8 -*- # Python import gzip inF =...
xah lee
p0lyglut
Offline Send Email
Sep 2, 2005
6:25 am

... You could shorten the Perl unix calls by using the backtick operator: `gzip x.txt` `gzip -d x.txt.gz` And for the same behaviour as the Python module,...
danny staple
orionrobots@...
Send Email
Sep 2, 2005
3:55 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help