473,508 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: GzipFile as a Context manager

En Wed, 19 Nov 2008 17:04:22 -0200, Mikolai Fajer <mf****@gmail.com>
escribió:
Is there a reason that the gzip.GzipFile class does not have __enter__
and __exit__ methods that mimic those of the file object? I expected
the following to work but it doesn't:

import gzip
with gzip.open('temp.gz', 'w') as fhandle:
gzip.write('Hello world.')

If there is no reason to avoid this behavior should I submit a bug
report and a subsequent patch? Thanks!
Several of those were added in Python 2.6, looks like GzipFile should
behave the same way.

--
Gabriel Genellina

Nov 21 '08 #1
0 1189

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

Similar topics

1
10265
by: SPG | last post by:
Hi, I am relatively new to TOMCAT, and am trying to deploy a web app using it. I have a domain name that I want to use to access my web app directly. By default, I deploy my WAR, and it deploys...
0
1031
by: Paulo da Silva | last post by:
Hi. I am writing to a file mixing "Normal" with gziped Data. For that I am using GzipFile. For ex. 1st I write some data (A), then I open a GzipFile and write let's say N (uncompressed) bytes...
0
1040
by: Justin Guerin | last post by:
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...
1
1527
by: Michael Speer | last post by:
I posted this to my blog at http://michaelspeer.blogspot.com/2007/11/context-manager-for-temporary.html. I decided to forward it onto the list for comments. I thought someone might find it...
0
941
by: Matt | last post by:
Hi all, I'm using the gzip module to return a gzip response from a small python httpserver. I'd like to know the number of bytes written to the underlying socket, but it doesn't seem to support...
3
1206
by: Floris Bruynooghe | last post by:
Hi I was wondering when it was worthwil to use context managers for file. Consider this example: def foo(): t = False for line in file('/tmp/foo'): if line.startswith('bar'): t = True
0
722
by: Brian Cole | last post by:
Appears like a patch was submitted to allow GzipFile to work from pipes long ago. But there's no comment on why this was never accepted. Is there a good reason? ...
4
1687
by: Daniel | last post by:
Hello, I need to access the code inside of a context manager, i.e. the call to with myManager(v=5) as x: a=b c=sin(x) should cause the following output (minus the first line, if that's...
0
1161
by: Mikolai Fajer | last post by:
Is there a reason that the gzip.GzipFile class does not have __enter__ and __exit__ methods that mimic those of the file object? I expected the following to work but it doesn't: import gzip...
0
7226
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7388
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...
1
5055
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4709
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3199
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...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
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 ...
1
767
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
422
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...

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.