Skip to content

Instantly share code, notes, and snippets.

@xuanyu-h
Created December 20, 2017 07:31
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 xuanyu-h/fde105c61c5e03c89039895c5acd575c to your computer and use it in GitHub Desktop.
Save xuanyu-h/fde105c61c5e03c89039895c5acd575c to your computer and use it in GitHub Desktop.
Python 单例模式
class AuthManager(object):
"""Authentication Manager."""
def __new__(cls):
singleton = cls.__dict__.get('__singleton__')
if singleton is not None:
return singleton
cls.__singleton__ = singleton = object.__new__(cls)
return singleton
def __init__(self):
self.passwd = {}
self._auth = {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment