I'm trying to learn how to implement singleton pattern in python. It seems little bit difficult to implement singleton pattern in python.i don't know it's becauses of the nature of the language.
This is what i tried
class Singleton(object):
_instance = None
def __new__(cls):
if cls._instance is not None:
pass
else:
cls._instance = super().__new__(cls)
return Singleton._instance
def getInstance():
return Singleton._instance
Does this code will create a singleton pattern, if it does is it a proper/good approach if it not what is bad about this code. I've read some SO questions and looked at the python data model documentation and this what i could come up with i wanna know what is the best approach in python to create a singleton pattern