Licheng Fang wrote: > I find myself frequently in need of classes like this for two > reasons. First, it's efficient in memory.
Are you using millions of objects, or MB size objects? Otherwise, this is no argument. BTW, what happens if you, by some operation, make a == b, and afterwards change b so another object instance must be created? This instance management is quite a runtime overhead. > Second, when two instances are compared for equality only their > pointers are compared. I state that the object management will often eat more performance than equality testing. Except you have a huge number of equal objects. If the latter was the case you should rethink your program design. > (I think that's how Python compares 'str's. Generally not. In CPython, just very short strings are created only once. >>> a=" " >>> b=" " >>> a is b True >>> a=" " >>> b=" " >>> a is b False Regards, Björn -- BOFH excuse #430: Mouse has out-of-cheese-error -- http://mail.python.org/mailman/listinfo/python-list