Cross platform difference: Object hex address case

Erik Max Francis max at alcyone.com
Tue Feb 25 18:42:45 EST 2003


Follower wrote:

> For at least release 2.2.1 there seems to be a difference in operation
> between Windows & Linux Python versions when an object's hexadecimal
> address is displayed.
> 
> Assume you have an object that has an id that in hexadecimal
> representation will contain one or more of the letters A-F.
> 
> If you call (explicitly or implicitly) __repr__() or __str__() the
> case of the letters used in the hexadecimal representation will differ
> between platforms.

For objects whose repr is a string of the form '<...>', it seems to me
that the entire contents of that string are implementation defined.  A
very common convention is that it prints a string of the form

	'<(type) (thing) at (ID)>'

but the actual composition of that ID is left unspecified.  Typically
it's the physical address of the object in memory, but even then the
appearance of that address is completely implementation defined; it
could, after all, simply be an integer that's incremented every time a
new object is created.  Even if it's an address, what might it look like
on a 16 bit system, for instance, or a segmented architecture?

Jython, for instance, doesn't even bother printing the ID in hexadecimal
form:

Jython 2.1 on java1.3.0 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> class C: pass
... 
>>> c = C()
>>> repr(C)
'<class __main__.C at 4539988>'
>>> repr(c)
'<__main__.C instance at 2353846>'

I concede that it is an inconsistency (0x%x vs. 0x%X), but there is no
time when an application should change its behavior based on the
contents of that portion of the repr string.  The entire realm of that
output is implementation defined, so it doesn't really _matter_ if
there's an inconsistency or not.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Grub first, then ethics.
\__/ Bertolt Brecht
    Polly Wanna Cracka? / http://www.pollywannacracka.com/
 The Internet resource for interracial relationships.




More information about the Python-list mailing list