Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. class Super:
  2. def __init__(self):
  3. self.data1 = 'spam'
  4. def ham(self): pass
  5.  
  6. class ListTree:
  7. def __str__(self):
  8. self.__visited = {}
  9. return '<Instance of {0}, adress {1}:n{2}{3}>'.format(
  10. self.__class__.__name__,
  11. id(self),
  12. self.__attrnames(self, 0),
  13. self.__listclass(self.__class__, 4))
  14. def __listclass(self, aClass, indent):
  15. dots = '.' * indent
  16. if aClass in self.__visited:
  17. return 'n{0}<Class {1}:, address {2}: (see above)>n'.format(
  18. dots,
  19. aClass,__name__,
  20. id(aClass))
  21. else:
  22. self.__visited[aClass] = True
  23. genabove = (self.__listclass(c, indent+4) for c in aClass.__bases__)
  24. return 'n{0}<Class {1}, address {2}:n{3}{4}{5}n'.format(
  25. dots,
  26. aClass.__name__,
  27. id(aClass),
  28. self.__attrnames(aClass, indent),
  29. ''.join(genabove),
  30. dots)
  31. def __attrnames(self, obj, indent):
  32. spaces = ' ' * (indent + 4)
  33. result = ''
  34. for attr in sorted(obj.__dict__):
  35. if attr.startswith('__') and attr.endswith('__'):
  36. result += spaces + '{0}=<>n'.format(attr)
  37. else:
  38. result += spaces + '{0}={1}n'.format(attr, getattr(obj, attr))
  39. return result
  40.  
  41.  
  42. class Sub(Super, ListTree):
  43. pass
  44.  
  45.  
  46. a = Sub()
  47. print(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement