Python global empty in class
Question: I tried to get array parameters values in another class , where and why i
wrong here ?

> My second python file => myModule.py :
    
    
    parameters  = ([])
    
    class MyFirstClass():
        def __init__(self, params):
            global parameters
            parameters = params
    
    class MySecondClass():
        def __init__(self):
            global parameters
            print parameters
    
    
    class MyClassWhereIHaveAProblem(http.HTTPFactory):
        proto = .....
        global parameters
        print parameters  **// array is empty here**
    
    class start_server():
         def __init__(self, params):
            self.x_params = params[0] //ip
            self.y_params = int(params[1]) //port
            global parameters 
            parameters = params[2]
         def start():
             reactor.listenTCP(self.y, MyClassWhereIHaveAProblem(), interface=self.x)
    

> My first python file => Handle.py :
    
    
    from myModule import MyFisrtClass
    from myModule import MySecondClass
    from myModule import MyClassWhereIHaveAProblem
    from myModule import start_server
    
    class Handle():
        def __init__(self):
            params = (["vector1", "vector2"])
            self.params = (["127.0.0.1","3128", params])
        def go_to_another(self):
            s = start_server(self.params)
            s.start()
    
    if __name__ == '__main__':
        H = Handle()
        H.go_to_another()
    

I tried to get array parameters values in another class , where and why i
wrong here ?


Answer: It looks like you are simply:

  * forgetting the second set of double underscores for the special method names 
  * making typos in the class names, you had "First" spelled "Fisrt"
  * you never did anything to use the `MySecondClass` class, so I initialized one in your main routine with: ` y = MySecondClass()`

> Handle.py:
    
    
    #!/usr/bin/env python 
    
    from myModule import MyFirstClass
    from myModule import MySecondClass
    
    class Handle():
        def __init__(self):
            self.params = (["ele1","ele2","ele3"])
        def go_to_another(self):
            X = MyFirstClass(self.params)
    
    if __name__ == '__main__':
        H = Handle()
        H.go_to_another()
        y = MySecondClass()
    

> myModule.py:
    
    
    #!/usr/bin/env python
    
    parameters = ([])
    
    class MyFirstClass():
        def __init__(self, params):
            global parameters
            parameters = params
    
    class MySecondClass():
        def __init__(self):
            global parameters
            print 'this should not be empty: %s' % parameters  # array is no longer empty here
    

> Output:
    
    
    this should not be empty: ['ele1', 'ele2', 'ele3']
    

