hex(id(...)) and negative id's, 6 questions

Gerrit gerrit at nl.linux.org
Sat Feb 7 05:37:54 EST 2004


Hi,

in my own classes, I usually implement __repr__ with something like:

            hex(id(obj))

...in order to simulate the behaviour of built-in types.

However, since I upgraded to Fedora Core 1 and Linux Kernel
2.4.22-1.2163.nptl, id(obj) is usually negative. Why is it negative?

Still, hex() returns a positive number when passed a negative argument. Why?
I can see that it will change, but why did it behave like this until 2.4?

Python 2.3.3 (#4, Feb  6 2004, 23:05:05)
[GCC 3.3.2 20040108 (Red Hat Linux 3.3.2-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> obj=object()
>>> hex(id(obj))
/home/gerrit/.pythonrc:1: FutureWarning: hex()/oct() of negative int
will return a signed string in Python 2.4 and up
  #!/usr/bin/env python
'0xbf59d3b8'
>>> obj
<object object at 0xbf59d3b8>
>>> hex(abs(id(object)))
'0x810ce20'

I see that obj still takes the positive part. It does not equal
hex(abs(...)). Why not? What is a signed string? And how do I keep behaving my
__repr__ like repr(obj) does in the future? How does repr(obj) bypass the
FutureWarning? 

That are, let me count, 6 questions ;-)

Gerrit.

-- 
PrePEP: Builtin path type
    http://people.nl.linux.org/~gerrit/creaties/path/pep-xxxx.html
Asperger's Syndrome - a personal approach:
	http://people.nl.linux.org/~gerrit/english/




More information about the Python-list mailing list