Skip to content

Instantly share code, notes, and snippets.



Created Jan 30, 2010
What would you like to do?
The shared instance implementation by using
captured lexical variable bindings.
class A(object):
def shared():
Returns the shared instance of A.
>>> A.shared() #doctest: +ELLIPSIS
<__main__.A ...>
>>> A.shared() is A.shared()
instance = A()
A.shared = staticmethod(lambda: instance)
return instance
if __name__ == "__main__":
import doctest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.