add a __repr__ method to StorableObject

It reports the name of the class, the id and if possible a display name.
This commit is contained in:
Benjamin Dauvergne 2012-10-04 10:00:58 +02:00
parent e4a9e5e72d
commit 8899e59ce3
1 changed files with 8 additions and 0 deletions

View File

@ -538,3 +538,11 @@ class StorableObject(object):
shutil.rmtree(tmpdir)
wipe = classmethod(wipe)
def __repr__(self):
if hasattr(self, 'display_name'):
display_name = '%r ' % self.display_name
elif hasattr(self, 'get_display_name'):
display_name = '%r ' % self.get_display_name()
else:
display_name = ''
return '<%s %sid:%s>' % (self.__class__.__name__, display_name, self.id)