Cross platform difference: Object hex address case

Follower follower at iname.com
Tue Feb 25 17:50:39 EST 2003


Hi,

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.

e.g.

Linux:

>>> oo.__repr__()
'<object object at 0x80a1118>'

Windows:

>>> oo.__repr__()
'<object object at 0x80A1118>'

Note that the 'a' is lowercase under Linux and upper case under
Windows.

Is this behaviour intentional? Desired? A bug?

If there is no justification for the difference I would like to
recommend that the difference be removed. As the hex() function
returns lowercase values under both Linux & Windows I'd suggest the
common form should use lower case hex values.

The reason this is a problem for me is that for a unit test I need to
be able to compare the string representation of an object to its
expected value. I am using code similar to:

obj = object()
assert("<object object at 0x%x>" % id(obj) == str(obj))

Obviously I could use "%X" as the formatter if I was always under
Windows, but considering hex() always returns the equivalent of "%x"
it would seem the Windows version's behaviour is non-standard.

--Phil.




More information about the Python-list mailing list