[Python-Dev] With statement
Michael Hudson
mwh@python.net
Wed, 05 Feb 2003 13:35:57 +0000
Oren Tirosh <oren-py-d@hishome.net> writes:
> Let's assume that a new 'local' statement is added to Python. At the end
> of the current block the __del__ method of any references declared local
> is guaranteed to be called. The object must have exactly one remaining
> reference, otherwise an exception is raised. In a GC implementation it may
> make some change to the object so that any remaining references to it
> become stale references and raise an exception as soon as they are touched
> in any way. Note that a reference to a closed file object is already a
> stale reference and raises an exception if any I/O operation is attempted
> on it.
Two comments:
1) The resource-allocation-is-initialization pattern works very well
in C++, but I'm unconvinced that we should aim to copy it exactly
-- it's a nice solution to the problem, but not the only possible
or best one, IMHO.
2) Without the ability to define a scope at will, RAiI becomes less useful.
Cheers,
M.
--
If your telephone company installs a system in the woods with no
one around to see them, do they still get it wrong?
-- Robert Moir, alt.sysadmin.recovery