How can I get an object's address for inclusion in the object representation, similar to how the default __repr__
works?
>>> a=object()
>>> a
<object object at 0x1002c8090>
class Foo(object):
def __repr__(self):
return '<my stuff, at '+obj_address+'>' # how do I get object address?
The address is the ID of the object in hex:
>>> o = object()
>>> repr(o)
'<object object at 0x1028ed080>'
>>> id(o)
4337881216
>>> hex(id(o))
'0x1028ed080'
class Foo(object):
def __repr__(self):
return '<my stuff, at 0x%x>' % id(self)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With