Skip to content

Instantly share code, notes, and snippets.

@pikhovkin
Created May 6, 2011 14:53
Show Gist options
  • Save pikhovkin/959076 to your computer and use it in GitHub Desktop.
Save pikhovkin/959076 to your computer and use it in GitHub Desktop.
class Keeper(object):
_instances = list()
def __new__(cls):
obj = object.__new__(cls)
cls.__init__(obj)
cls._instances.append(obj)
@classmethod
def list_instances(self):
for instance in self._instances:
yield instance
def __str__(self):
return '<%s instance at 0x%X>' % (self.__class__.__name__, id(self))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment