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
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/c.../pep-xxxx.html
Asperger's Syndrome - a personal approach:
http://people.nl.linux.org/~gerrit/english/

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.