'reload M' doesn't update 'from M inport *'

Aahz aahz at pythoncraft.com
Sat Jul 17 20:09:42 EDT 2010


In article <mailman.616.1278927754.1673.python-list at python.org>,
Jean-Michel Pichavant  <jeanmichel at sequans.com> wrote:
>Aahz wrote:
>> In article <mailman.488.1278697107.1673.python-list at python.org>,
>> Jean-Michel Pichavant  <jeanmichel at sequans.com> wrote:
>>>
>>> PS : You're misusing the del statement. It does not remove any object 
>>> from mmory, however, it removes the reference to it, the object is still 
>>> in memory. They are very few cases where del is usefull in python, so 
>>> try to avoid using it as well.
>>
>> The first two sentences are true; the last sentence is completely wrong.
>> I've got lots of code using del, and it's a critically useful element of
>> dictionary manipulation.
>   
>Can you please give a short example ? I'm not challenging though, just 
>curious.

Let's suppose you want to remove duplicate keys from a second dict:

for k in d1:
    if k in d2:
        del d2[k]

You could do d2.pop() instead, but I'll bet you'll find that it's
slightly slower, which makes a difference in a tight loop.  (Mainly,
though, I learned this idiom long before pop() was available.)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"....Normal is what cuts off your sixth finger and your tail..."  --Siobhan



More information about the Python-list mailing list