title: Python - pass variables from a subroutine to the main program
body: <p>I would like to call a subroutine to gather data.  This is in a loop.  So each iteration I would like to write to an excel file.  I could just copy the subroutine into the main program, but would like a cleaner way to do this.  I have something like this:</p>
  
  <pre><code>#This creates my path and file name to open later
  path = os.getcwd()
  filetime = time.strftime("_%Y_%H_%M_%S", time.localtime()) 
  fname = 'Test'
  fext = '.csv'
  fpath = path + '/' + fname + filetime + fext
  
  
  #start of loop
  for val1 in range(5):
      for val in range(6):
          #write some register with val1
          #write some register with val2
          subprocess.call("test.py", shell=True)
          #this subprosses does something that spits out data for 8 variables a through h
  
          #I would like to write that data into the path and file I created above
          data=open(fpath, 'a')
          #data.write('%.2f\n' % (cl))
          data.write('%i,%i,%i,%.2f,%.2f,%.2f,%.2f,%.2f\n' % (a,b,c,d,e,f,g,h))
          data.close()
  </code></pre>
  
  <h1>Now that I have the data written, would like to go through all iteration of loop and append the data into the file</h1>