Searching equivalent to C++ RAII or deterministic destructors

Aahz aahz at pythoncraft.com
Sat Jul 4 06:50:47 CEST 2009


In article <ftps459nklqio3nghaaraniqo3fs9r8ck8 at 4ax.com>,
Tim Roberts  <timr at probo.com> wrote:
>Dave Angel <davea at dejaviewphoto.com> wrote:
>>   
>>You're right of course.  What I was trying to say was it deletes the 
>>reference to the object.  Unlike obj = None, del obj removes the 
>>reference (attribute) entirely. Although I don't know what it should be 
>>called if it's a local variable.  Perhaps it "unbinds" the name.
>
>Yes.  As far as the object is concerned, "obj = None" and "del obj" are
>exactly identical.  In both cases, there is one less binding to the name.
>
>The difference between the two is only whether the name lives on in the
>namespace.
>
>A local variable is (usually) just a name in the local() namespace.

OTOH, Python's ``del`` applies to targets generally, not just names:

>>> L = [1,2,3]
>>> del L[1]
>>> L
[1, 3]
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha



More information about the Python-list mailing list