hex(id(...)) and negative id's, 6 questions
Dietrich Epp
dietrich at zdome.net
Thu Feb 12 19:12:24 EST 2004
On Feb 10, 2004, at 2:12 PM, Gerrit wrote:
> ...and the base class happens to define __repr__, which does not
> include
> id(self). I want to be able to see in debugging code that a certain
> sprite at pos (x1, y1) at frame N is the same as a certain sprite at
> position (x2, y2) in frame M. id(self) seems ideal for that, until
> these
> Warnings started (I now do abs(id(self)), which is ugly enough but gets
> rid of the warning).
>
> Any hints on getting this right? Parsing object.__repr__(self) is not
> the best solution either ;-)
abs(id(self)) is a kludge, it could theoretically result in two
different objects appearing to be the same (but one object would have
to be misaligned). Try:
hex(id(self) & 0xFFFFFFFFL)
Personally, I think the handling of negative numbers as 32-bit strings
got a little messed up now that Python complains when you try to print
them in hexadecimal. It would be nice if there were a format string
for printing them that way, maybe there is?
More information about the Python-list
mailing list