Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- class Test():
- instances = []
- def __init__(self, name):
- self.name = name
- self.register(self)
- #vagy legyen inkább: self.__class__.register(self) ?
- @classmethod
- def register(cls,instance):
- cls.instances.append(instance)
- @classmethod
- def kill(cls,name):
- for instance in cls.instances:
- if instance.name == name:
- cls.instances.remove(instance)
- @classmethod
- def print_instances(cls):
- for instance in cls.instances:
- print(instance, instance.name)
- for name in ['Alpha', 'Beta', 'Gamma']:
- Test(name)
- Test.print_instances()
- Test.kill('Alpha')
- Test.print_instances()
Advertisement
Add Comment
Please, Sign In to add comment