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