Re [Python-Dev] object equality vs identity, in and dicts idioms and speed
Finn Bock
bckfnn@worldonline.dk
Fri, 04 Jan 2002 22:11:29 GMT
[Martin v. Loewis]
>I understand Samuele was talking about mapping in the Python sense
>(existance of dictionary-style containers); he also mentioned that
>Jython creates a Python wrapper object for each "foreign" Java object.
Your summery is quite accurate.
When this was discussed on jython-dev, I said I preferred a solution
where all objects was inserted in your "map" dictionary when id() was
called on them. Not just the wrapped java instances. I picked that
preference because I think using id() is a relative uncommon operation.
In the Lib modules, id() is used to detect cycles in copy.py, pickle.py,
pprint.py and xmlrpclib. I would rather have a slow id() operation on
python objects too, than burden all python objects with an additional
int or long.
Is that a wrong call?
In the repr() of a lot of internal objects, the id() is used in the
return string. Would anyone rightly expect that hex number to match the
id() value of the object? In our discussions we agreed that the repr()
string does not have to match the value return by id().
regards,
finn