Note that there are some explanatory texts on larger screens.

plurals
  1. POPython : Object is not avaialbe on different file
    primarykey
    data
    text
    <p>I have created a singlton Here is the class description.<br> allsms.py</p> <pre><code>from DB.models import ApiKey,ServiceProvider from DB.messagenet import MessageNet class SMSMgr( object ): _instance = None _allsp = [] def __init__(self): pass def __new__(cls, *args, **kwargs): if not cls._instance : cls._instance = super(SMSMgr, cls).__new__( cls, *args, **kwargs) return cls._instance def loadsettings(self): get_all_sp = ServiceProvider.objects.filter(status = False) for obj in get_all_sp: cla = obj.class_Name a=globals()[str(obj.class_Name)](obj.userName,obj.password,obj.sendingurl) self._allsp.append(a) #print self._allsp def reload(self): self._allsp = [] get_all_sp = ServiceProvider.objects.filter(status = False) for obj in get_all_sp: cla = obj.class_Name a=globals()[str(obj.class_Name)](obj.userName,obj.password,obj.sendingurl) self._allsp.append(a) def send(self): print "+++++++++++++++++++== Global send " if __name__ == "__main__": b = SMSMgr() b.loadsettings() </code></pre> <p>Now in <code>test.py</code> file of the same directory I am trying to use the singleton object which stored in the <code>_allsp</code> variable like.</p> <pre><code>from SMShandler.allsms import SMSMgr b = SMSMgr() #b.loadsettings() print b._allsp </code></pre> <p>This is printing empty list. But when I am doing like this:</p> <pre><code>b = SMSMgr() b.loadsettings() print b._allsp </code></pre> <p>it is printing the list of objects .</p> <p>My question is, if the above design is singlton then why <code>print b._allsp</code> is printing empty list in <code>test.py</code>? I am already loading <code>loadsettings</code> in the <code>allsms.py</code> file . </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload