dimanche 10 juillet 2016

Can a particular instance of a class declared in a python file be accessed from another file?


I have a class which have several functions in it. In file1, I have created an instance of that class.

class requestHandler():
  def __init__(self):
       ......

  def processRequest(self,command):
       ......
if __name__ == "__main__" :
   currentHandler = requestHandler()

Now, I want to access this 'currentHandler' instance from another file. I have tried several ways, but have been failed. If I try like this:

import file1

class adapter:
    def __init__(self):
         command = "move"
         .......

    def processRequest(self):
         d = file1.requestHandler()
         d.processRequest(command)

It creates a new instance of 'requestHandler' class. But I do not want that.

Can someone please help me in this regard? Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire