From 3234d7c2944e9abfd3541ba44ed1ab10290f7f0a Mon Sep 17 00:00:00 2001 From: Ahsanuzzaman Khan Date: Mon, 25 Jul 2016 18:15:10 +0600 Subject: [PATCH] Create simple singleton pattern. --- singleton.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 singleton.py diff --git a/singleton.py b/singleton.py new file mode 100644 index 00000000..5a251667 --- /dev/null +++ b/singleton.py @@ -0,0 +1,12 @@ +class Singleton(object): + ''' + Share single instance of this class, initially created one + ''' + instance = None + + def __new__(cls): + if Singleton.instance is not None: + return Singleton.instance + + Singleton.instance = object.__new__(cls) + return Singleton.instance