[Python-Dev] Resource leaks warnings

Hrvoje Niksic hrvoje.niksic at avl.com
Wed Sep 29 15:16:14 CEST 2010

On 09/29/2010 02:42 PM, Antoine Pitrou wrote:
>>  It seems like a slippery slope. Sometimes you really don't care like
>>  when you're just hacking together a quick script.
> Isn't the "with" statement appropriate in these cases?

A hacked-together quick script might contain code like:


Compared to this, "with" adds a new indentation level and a new 
variable, while breaking the flow of the code:

with open(bla) as foo:
     contents = foo.read()

People used to writing production code under stringent guidelines 
(introduced for good reason) will probably not be sympathetic to 
quick-hack usage patterns, but Python is used on both sides of the fence.

More information about the Python-Dev mailing list