Cross platform difference: Object hex address case

Chermside, Michael mchermside at
Wed Feb 26 21:48:24 CET 2003

> I'm tempted to show how the *actual* test works, but in the end it's
> fairly inconsequential, so I won't waste anyone's time. But if
> "cleverer" means "better", how would *you* test it? (Admittedly, my
> original example didn't show the "embedded" nature of my actual usage
> of the string representation of the object.)

Tim Peters:
> I can't say, because I don't know what you're actually trying to test.  In
> over a decade of using Python, I've never had the slightest temptation to
> test for reproducibility of memory addresses, and that's all the original
> showed.

I agree with Tim... why on earth would you need to do this?! But
a really simple way to do exactly what you're asking for is this:

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

-- Michael Chermside

More information about the Python-list mailing list