Arnaud Delobelle <[EMAIL PROTECTED]> wrote:

> 
> 
> Duncan Booth wrote:
>> Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>>
>> >
>> >
>> > George Sakkis wrote:
>> >> One of the few Python constructs that feels less elegant than
>> >> necessary to me is the del statement. For one thing, it is 
overloaded
>> >> to mean three different things:
>> >> (1) del x: Remove x from the current namespace
>> >> (2) del x[i]: Equivalent to x.__delitem__(i)
>> >> (3) del x.a: Equivalent to x.__delattr__('a') (or delattr(x,'a'))
>> >
>> > Note that the 'X = Y' construct has the corresponding three 
meanings:
>> >
>> > (1) x = 4 # Bind x to 4 in the 'current namespace'
>> > (2) x[i] = 4 # equivalent to x.__setitem__(i, 4)
>> > (3) x.a = 4 # Equivalent to x.__setattr__('a', 4)
>>
>> I think you both missed a case:
>>
>>   (1b) global x; del x    # Remove x from global namespace
>>   (1b) global x; x = 4    # Bind x to 4 in the global namespace
> 
> This is why you put 'current namespace' in quotes!  But all three of
> us missed the case:

I'd assumed you were just trying to say that the current namespace might 
be different things: locals or a class namespace. I would say that the 
global statement makes the assign/del refer to a non-current namespace.

> 
> (1-3000) What about nonlocal?

What about nonlocal? You can't (in Python 2.x) assign or del a name from 
an enclosing scope if that's what you mean. If that isn't what you mean 
then you'll have to explain it to me in simpler terms.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to