473,666 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.read line()
tellold = tellnew
tellnew = oldfileobj.tell ()
oldmd5.update(l ine)
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.read lines()"

Thanks for the pointers.

Justin Guerin
Jul 18 '05 #1
0 1049

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1382
by: Greg Bakken | last post by:
I am writing a python program that recieves 'compressed and encoded' strings from another piece of software. I can successfully uncompress and decode the strings via import base64, zlib def getString(s): s = base64.decodestring(s) s = zlib.decompress(s, -15) return s
3
4574
by: rohisingh | last post by:
I have a tar file. The content of the file are as following. rohits@sandman 12-08-04 $ tar tvf 20041208.tar drwxr-xr-x root/root 0 2004-12-08 21:39:19 20041208/ -rw-r--r-- root/root 1576 2004-12-08 21:39:19 20041208/README drwxr-xr-x root/root 0 2004-12-08 21:27:31 20041208/snapshot_01/ -rw-r--r-- was/was 103010606 2004-12-08 16:37:38 20041208/snapshot_01/tpv-2004 1208-1350.xml.gz
10
3905
by: Xah Lee | last post by:
today i need to use Python to decompress gzip files. since i'm familiar with Python doc and have 10 years of computing experience with 4 years in unix admin and perl, i have quickly located the official doc: http://python.org/doc/2.4.1/lib/module-gzip.html but after a minute of scanning, please someone tell me what the fuck is it talking about?
14
7127
by: Bill | last post by:
I've written a small program that, in part, reads in a file and parses it. Sometimes, the file is gzipped. The code that I use to get the file object is like so: if filename.endswith(".gz"): file = GzipFile(filename) else: file = open(filename) Then I parse the contents of the file in the usual way (for line in
3
6166
by: bob | last post by:
I'm using the code below to read the zipped, base64 encoded WMF file saved in an XML file with "Save as XML" from MS Word. As the "At this point" comment shows, I know that the base64 decoding is going fine, but unzipping from the decodedVersion StringIO object isn't getting me anything, because the len(fileContent) call is returning 0. Any suggestions? thanks, Bob
1
2170
by: Nader | last post by:
Hello, I have a gzip file and I try to read from this file withe the next statements: gunziped_file = gzip.GzipFile('gzip-file') input_file = open(gunziped_file,'r') But I get the nezt error message:
1
2101
by: Nader | last post by:
Hello, I have a gzip file and I try to read from this file withe the next statements: gunziped_file = gzip.GzipFile('gzip-file') input_file = open(gunziped_file,'r') But I get the nezt error message:
0
1283
by: Gabriel Genellina | last post by:
En Wed, 19 Nov 2008 13:25:03 -0200, Barak, Ron <Ron.Barak@lsi.com> escribió: Note *where* the exception is raised. Until something is actually read, no check is made for the file format. -- Gabriel Genellina
0
1959
by: Barak, Ron | last post by:
Thanks Gabriel, Okay, I get it: I was under the impression that the format check would be done on the open. Bye, Ron. -----Original Message----- From: Gabriel Genellina Sent: Thursday, November 20, 2008 02:06 To: python-list@python.org Subject: Re: Why is try...except in my code not working (gzip/text files) ?
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8783
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8552
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.