Skip to content

Instantly share code, notes, and snippets.

@netman92
Forked from 1st/singleton.py
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netman92/e799a76f86520d274f46 to your computer and use it in GitHub Desktop.
Save netman92/e799a76f86520d274f46 to your computer and use it in GitHub Desktop.
Singleton implantation on Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class Singleton(type):
def __call__(self, *args, **kwargs):
if 'instance' not in self.__dict__:
self.instance = super(Singleton, self).__call__(*args, **kwargs)
return self.instance
class CoolFeautre(object):
__metaclass__ = Singleton
print CoolFeautre()
print CoolFeautre()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment