| f | import weakref | f | import weakref |
| | | |
| class Borg: | | class Borg: |
| n | _instances = [] | n | _all = [] |
| | | |
| def __init__(self, value=0): | | def __init__(self, value=0): |
| n | self.value = value | n | self._value = value |
| Borg._instances.append(weakref.ref(self)) | | Borg._all.append(weakref.ref(self)) |
| | | |
| def __str__(self): | | def __str__(self): |
| n | return str(self.value) | n | return str(self._value) |
| | | |
| def __iter__(self): | | def __iter__(self): |
| n | for ref in Borg._instances: | n | for ref in Borg._all: |
| instance = ref() | | inst = ref() |
| if instance is not None: | | if inst is not None: |
| yield instance.value | | yield inst._value |
| | | |
| n | def __iadd__(self, other): | n | def __iadd__(self, num): |
| for ref in Borg._instances: | | for ref in Borg._all: |
| instance = ref() | | inst = ref() |
| if instance is not None: | | if inst is not None: |
| instance.value += other | | inst._value += num |
| return self | | return self |
| | | |
| t | def __isub__(self, other): | t | def __isub__(self, num): |
| for ref in Borg._instances: | | for ref in Borg._all: |
| instance = ref() | | inst = ref() |
| if instance is not None: | | if inst is not None: |
| instance.value -= other | | inst._value -= num |
| return self | | return self |