Skip to content

Instantly share code, notes, and snippets.

@bl4ck5un
Created May 10, 2014 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bl4ck5un/e278d16fab3b60e029a8 to your computer and use it in GitHub Desktop.
Save bl4ck5un/e278d16fab3b60e029a8 to your computer and use it in GitHub Desktop.
A Python class-tree climber
#!/usr/share/python
class ListInstance:
def __str__(self):
return '<Instance of %s, address %s:\n%s>' % (
self.__class__.__name__,
id(self),
self.__attrnames())
def __attrnames(self):
result = ''
for attr in dir(self):
if attr[:2] == '__' and attr[-2:] == '__':
result += '\tname %s=<>\n' % attr
else:
result += '\tname %s=%s\n' % (attr, getattr(self, attr))
return result
class Super:
def __init__(self):
self.data1 = 'spam'
def hem(self):
pass
class Sub(Super, ListInstance):
def __init__(self):
Super.__init__(self)
self.data2 = 'eggs'
self.data3 = 42
def spam():
pass
if __name__ == '__main__':
X = Sub()
print(X)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment