title: Subprogram which takes all the predefined variables from a "main program"
body: <p>i have a hard time with this:
  As i am programming GUIs with pyqt i want to structure my work:</p>
  
  <p>I have several buttons on my GUI that should call "different subprograms" from my calculations with scikitlearn.</p>
  
  <p>i have a button "PRED" for Prediction, another one for some plots called "PLOT"</p>
  
  <p>when these buttons are clicked a python "calculation program" is called with</p>
  
  <pre><code>class MyDia(QtGui.QDialog, Dlg): 
      def __init__(self): 
          QtGui.QDialog.__init__(self) 
          self.setupUi(self)
  
          self.connect(self.buttonOPLOT, 
                  QtCore.SIGNAL("clicked()"), self.onPLOT)    
          self.connect(self.buttonPRED, 
                  QtCore.SIGNAL("clicked()"), self.onPRED)
      def onPRED
          if self.button_1.checkState(): 
              a=1
          if self.button_2.checkState(): 
              a=2
          query=np.zeros((1,18))
          for i in range(0,18,1):
              try:
                  query[0,i]= float(self.tableWidget.item(0,i).text())
  
          ### when user has made his choices the data goes do this
          from sk_calc import main, pred
          main() #after main, "pred" should be called with some definitions that 
          have been made in "main"
          pred(a) #a is some parameter of a regression (i try to keep it easy)
  </code></pre>
  
  <p>at the moment i use different "calculation" programms "sk_plot and sk_pred" in different files- the goal is to change only ONE... where "main" runs before the specifiv job( PRED or PLOT...)</p>
  
  <p>THE UNIQUE calculation program should "look"/ be structured similar to this:</p>
  
  <pre><code>def main():
      import numpy as np
      import #all modules from scikitlearn
  
      DATA=np.genfromtxt(direc+"\some.csv",delimiter=";",dtype=float ,skip_header=2, usecols=range(0,22)) #reading in a csv file with my data
  
      features=DATA[:,4:22]#the "X" of my DATA
      targets=DATA[:,1]#the "Y" of my DATA
  
      svr_rbf = SVR(kernel='rbf', C=2e4, gamma=a) #Regression using the DATA #a comes from user click
      svr_rbf.fit(features, targets).predict(features)# method of scikit-learn
  
          def pred():
              Prediction=svr_rbf.predict(query)
              #query is defined by the user in the gui typing in some values 
              print(Pred_ic)
  
          def plot():
              #... something different using pylab but ALSO DATA features and targets
  </code></pre>
  
  <p>You See that i want that some code (main) runs unindependantly whick button is clicked 
  ,afterwards a part of the "calculation program" should be executed that has variables and DATA defined in main().</p>
  
  <p>Do i use a class for this? If yes, what do i have to keep in mind? What are the steps for this...</p>