Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. class MyList:
  2. def __init__(self, start=[]):
  3. print('__init__ method')
  4. self.list = list(start)
  5.  
  6. if __name__ == '__main__':
  7. M = MyList([2,4,7,8,9,2,3,4])
  8. print(M.list)
  9.  
  10. def __str__(self):
  11. return "__repr__ method: {0}".format(self.list)
  12.  
  13. class MyList:
  14. def __init__(self, start=[]):
  15. print('__init__ method')
  16. self.list = list(start)
  17.  
  18. def __repr__(self):
  19. return "__repr__ method: {0}".format(self.list)
  20.  
  21. def __getattr__(self, item):
  22. print('__getattr__ method')
  23. return getattr(self.list, item)
  24.  
  25. def __setattr__(self, key, value):
  26. print('__setattr__ method')
  27. if key == 'boolAttr':
  28. self.__dict__['boolAttr'] = False
  29. else:
  30. self.__dict__[key] = value
  31.  
  32. if __name__ == '__main__':
  33. M = MyList([2,4,7,8,9,2,3,4])
  34. print(M.list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement