The del statement
Dustan
DustanGroups at gmail.com
Tue Dec 5 07:14:43 EST 2006
Marco Aschwanden wrote:
> > do you find the x[i] syntax for calling the getitem/setitem methods a
> > bit awkward too? what about HTTP's use of "GET" and "POST" for most
> > about everything ? ;-)
>
> No. I like the x[i] syntax. I use it in every second row of my code and
> getting an item like:
>
> x.getitem(i)
That's spelled "x.__getitem__(i)". Still prefer the method call?
> would be a viable (in this case clumsy) way but here I find the introduced
> syntax justified.
> del on the other hand is used sparingly througout my code. If no del
> keyword would exist, it wouldn't disturb me.
"del x[i]" calls "x.__delitem__(i)". I can't say specifically what
list.__delitem__ does, but looking it up in IDLE (l is an instance of
list):
>>> l.remove
<built-in method remove of list object at 0x00C3ABE8>
>>> l.__getitem__
<built-in method __getitem__ of list object at 0x00C3ABE8>
>>> l.__delitem__
<method-wrapper '__delitem__' of list object at 0x00C3ABE8>
It seems that list.__delitem__ is a different type than the rest,
called method-wrapper. I can only guess from this point; someone else
is bound to know about this.
> Marco
I can see some builtin functions leaving, but the del keyword isn't
exactly unimportant. Looking at the documentation on the del statement:
http://docs.python.org/ref/del.html
There is no note saying that del is deprecated. That really doesn't
mean anything; it could always become deprecated in the future, but it
doesn't seem likely.
More information about the Python-list
mailing list