By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,592 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,592 IT Pros & Developers. It's quick & easy.

how to close a gzip.GzipFile?

P: n/a
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 =
tellold = 0
tellnew = 1
while tellold != tellnew:
line = oldfileobj.readline()
tellold = tellnew
tellnew = oldfileobj.tell()
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.