I want to extend the __str__()
method of my object. The str(obj)
currently reads:
<mymodule.Test object at 0x2b1f5098f2d0>
I like the address as a unique identifier, but I want to add some attributes. What's the best way to extend this while still keeping the address portion? I'd like to look something like this:
<mymodule.Test object at 0x2b1f5098f2d: name=foo, isValid=true>
I dont' see any attribute that stores the address. I'm using python 2.4.3.
Edit: Would be nice to know how to do this with __repr__()
Solution (for python 2.4.3):
def __repr__(self):
return "<%s.%s object at %s, name=%s, isValid=%s>" % (self.__module__,
self.__class__.__name__, hex(id(self)), self.name, self.isValid)