newbee: adress of object

Steve Holden sholden at
Mon Aug 5 08:17:32 EDT 2002

"Alexander Eisenhuth" <stacom at> wrote in message
news:3D4E4CE3.60207 at
> hallo together,
> for tracing i need to access the objects adress. I thougt about:
> class X:
> ...
>     log (self):
>       print 'myaddr:%s ...' % (self,...)

1. Nope, that will print the object's repr(), which foir a classic-class
instance will be something like  "<__main__.A instance at 0x100fc828>". You
could, of course, write a function to *parse* that and extract the address.

2. If you don't mind relying on what's currently an implementation detail,
for which I don't believe there are any guarantees of forward compatibilty,
you might notice that

>>> "address %s" % a
'address <__main__.A instance at 0x100fc828>'
>>> id(a)
>>> hex(id(a))

In other words, the id() of an object is exactly what you are looking for.

still-not-sure-why-you-need-the-address-though-ly y'rs  - steve
Steve Holden                       
Python Web Programming      

More information about the Python-list mailing list