title: How to import variable (sensor input) & update it from one python script to another?
body: <p>I'm currently setting up a some sensors with my raspberry pi in python. Total python newbie here.  </p>
  
  <p>Each sensor has it's own script to read the sensor and there is another script that drives an LCD display and displays the imported variable from the sensor script. </p>
  
  <p>I've gotten so far with working scripts that run the sensors and generate output, however, I cannot seem to import the variables (temperature &amp; pH) into the LCD display script. Also, once I have imported the variables, how do I instruct the LCD script to "refresh" the and fetch the updated variable? </p>
  
  <p>Here's a trimmed down version of what I have so far, I've omitted the sensor and data logging parts of each script. For simplicity, script_display is the LCD driver, and pH_script is for pH and temp_script is for temperature. </p>
  
  <p>Here's a simplified version of the scripts:</p>
  
  <h1>script_display.py</h1>
  
  <pre><code>import sys
  sys.path.insert(0, '/home/pi/Raspberry-Pi-sample-code')
  import pH_script
  import temp_script
  from ph_script import ph_main
  from temp_script import get_temp
  import time
  
  while True:
          print PH.ph_main(ph_output)
          print get_temp(temp)
          time.sleep(1)
  </code></pre>
  
  <h1>temp_script.py</h1>
  
  <pre><code>from w1thermsensor import W1ThermSensor
  import time
  
  #Get Temperature
  def get_temp():
          global temp
          sensor = W1ThermSensor(W1ThermSensor.THERM_SENSOR_DS18B20, "031683a0a4ff")
          activate_temp = sensor.get_temperature()
          temp = str(activate_temp)
          return temp
  
  #Read Temp Frequency
  def read():
          threading.Timer(0.5, read).start()
          get_temp()
          time.sleep(1)
  
  
    try:
              while True:
                      read()
                      get_temp()
                      print get_temp()
    except KeyboardInterrupt:               
          print("Program Ended By User")
  </code></pre>
  
  <h1>pH_script.py</h1>
  
  <pre><code>def ph_main():
  </code></pre>
  
  <p><em>lots and lots of code to activate the PH probe, and other variables, but the variable ph_output returns as a string, ph_output</em></p>
  
  <pre><code>    try:
          while True:
  
                    global ph_output
                    dev.send_cmd("R")
                    lines = dev.read_lines()
                    for i in range(len(lines)):
                                  print lines[i]
                                  if lines[i][0] != '*':
                                           print lines[i]
                                           ph_output = str(lines[i])
                                           return ph_output
                                           time.sleep(delaytime)
  try:
          while True:
                  ph_main() 
  
     except KeyboardInterrupt:               
                  print("Continuous polling stopped")
  </code></pre>
  
  <p>so, again, first question, how to pass the global variables back to the display script? and two, how to instruct the display script to 'refresh' the variables? </p>
  
  <p>the error I am currently getting is: </p>
  
  <pre><code>    Traceback (most recent call last):
    File "script_display.py", line 8, in &lt;module&gt;
      print PH.ph_main(ph_output)
  NameError: name 'ph_output' is not defined
  </code></pre>
  
  <p>looking forward to any input and thanks for your time + help!</p>