Created
May 10, 2014 16:28
-
-
Save bl4ck5un/e278d16fab3b60e029a8 to your computer and use it in GitHub Desktop.
A Python class-tree climber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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