By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,957 Members | 2,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,957 IT Pros & Developers. It's quick & easy.

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

P: n/a

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

hex(id(obj)) 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.
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)))


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

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


PrePEP: Builtin path type
Asperger's Syndrome - a personal approach:

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.