A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-February/032822.html below:

[Python-Dev] Acquire/release functionality

[Python-Dev] Acquire/release functionalityAahz aahz@pythoncraft.com
Mon, 3 Feb 2003 10:13:35 -0500
On Mon, Feb 03, 2003, Moore, Paul wrote:
>
> In trying to draw a parallel between "with" and the C++ RAII idiom, I
> hit a funny, best illustrated by an example:
> 
>     class autoclose(file):
>         __exit__ = close
> 
>     with f = autoclose("blah.txt", "r"):
>         # Let's get sneaky
>         g = f
>         # Main code here
> 
>     # File now gets closed
>     with g:
>        # Who's a naughty boy then - g is a closed file
>     # And the g.__exit__() call goes boom here...
> 
> OK, it's contrived. The equivalent C++ risk is that of creating a dangling
> pointer to a local variable which is deleted, which is also rare.

It's not at all contrived.  And I think it's perfectly acceptable; it's
no different, fundamentally, from calling f.close() twice by mistake.
-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Argue for your limitations, and sure enough they're yours."  --Richard Bach



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4