Question:

Can you create singleton object in python?If yes, how do you do it?

Answer:

Yes, you can create singleton object. Here’s how you do it :

class Singleton(object):
      def __new__(cls,*args,**kwargs):
          if not hasattr(cls,'_inst'):
             cls._inst = super(Singleton,cls).__new__(cls,*args,**kwargs)
          return cls._inst

 


Keywords:

© 2017 QuizBucket.org