Guest User

Untitled

a guest
May 19th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. class Test():
  4.  
  5. instances = []
  6.  
  7. def __init__(self, name):
  8. self.name = name
  9. Test.register(self)
  10. #vagy legyen inkább: self.__class__.register(self) ?
  11.  
  12.  
  13. @staticmethod
  14. def register(instance):
  15. Test.instances.append(instance)
  16.  
  17. @staticmethod
  18. def kill(name):
  19. for instance in Test.instances:
  20. if instance.name == name:
  21. Test.instances.remove(instance)
  22.  
  23. @staticmethod
  24. def print_instances():
  25. for instance in Test.instances:
  26. print(instance, instance.name)
  27.  
  28. for name in ['Alpha', 'Beta', 'Gamma']:
  29. Test(name)
  30.  
  31. Test.print_instances()
  32.  
  33. Test.kill('Alpha')
  34.  
  35. Test.print_instances()
Advertisement
Add Comment
Please, Sign In to add comment