using variable from one module class in another module class


#1

hi there,

I’m trying to organise my big script into a package, breaking different functions into their own modules.

I have a GUI module which contains a class that runs my interface and stores user input. This user input is stored in variables, and then with a button the user can trigger the main module which has its own class that needs to use the user input variables to run.

my question is how can i use a variable created in a class in one module and use it in a class in another module?

(Im trying to figure out if i actually need a class for some of the modules. But i think there are internal variables that need to see each other.)

thanks,
Sam


#2

Well, the obvious way would be to use the variable in the constructor of the other class, or let the methods explicitly use arguments:

import anotherModule as am

class GUIClass:
    def __init__():
         self.theOtherClass = am()

    def buttonPressed(self, whichButton):
         self.theOtherClass.doSomething(whichButton)
           ...

But I think you only need a class if you have to store informations during the usage of the class, maybe simple functions are enough.


#3

thanks alot Haggi