which methods to use?

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Fri Mar 30 15:01:43 CEST 2007


On Thu, 29 Mar 2007 14:55:04 -0300, Gabriel Genellina wrote:

> En Thu, 29 Mar 2007 01:56:15 -0300, Steven D'Aprano  
> <steve at REMOVE.THIS.cybersource.com.au> escribió:
> 
>> By the way, "id(obj) == id(another_object)" is just a long way of writing
>> "obj is another_object".
> 
> Just as a side note: that's not true, testing by id() only works if both  
> objects are alive at the same time.

Correction noted.


> py> id(object()) == id(object())
> True
> py> object() is object()
> False

That's weird. How on earth does that happen?


> So using the `is` operator is the only safe way to test for identity.

But if an object can be garbage collected before the is operator does the
comparison, how can that be safe?


-- 
Steven.




More information about the Python-list mailing list