469,352 Members | 2,163 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

how to close a gzip.GzipFile?

Hello list,

gzip documentation states that calling the .close() method on a GzipFile
doesn't really close it. If I'm really through with it, what's the best
way to close it? I'm using Python2.2 (but the gzip module doesn't seem to
be any different from 2.4).

Here's my code snippet, if it's relevant:

oldfileobj= file(oldfile, 'r')
oldmd5 = md5.new()
tellold = 0
tellnew = 1
while tellold != tellnew:
line = oldfileobj.readline()
tellold = tellnew
tellnew = oldfileobj.tell()
oldmd5.update(line)
At this point, I'm finished reading the file, and would like to properly
close it. Should I just del oldfileobj?

Also, while I'm asking, does anyone know a better way to iterate through a
gzipped file? The gzip module doesn't support iteration, nor xreadlines.
I need to avoid reading the entire file contents into memory, so I can't
use "for line in oldfileobj.readlines()"

Thanks for the pointers.

Justin Guerin
Jul 18 '05 #1
0 956

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Greg Bakken | last post: by
3 posts views Thread by rohisingh | last post: by
10 posts views Thread by Xah Lee | last post: by
14 posts views Thread by Bill | last post: by
3 posts views Thread by bob | last post: by
1 post views Thread by Nader | last post: by
1 post views Thread by Nader | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.