title: ROS How to pass a callback variable into another file?
body: <p>I have a callback function in a file &quot;color.py&quot; that constantly recieves incoming data but updates a global variable every 3 seconds:</p>
  <pre><code>last_color = &quot;&quot;
  last_calltime = datetime.strptime(&quot;00:00:00&quot;,&quot;%H:%M:%S&quot;)
  
  def callback(data):
     global last_calltime, last_color
     cube = data.data
     t = time.localtime()
     tf = time.strftime(&quot;%H:%M:%S&quot;,t)
     current_time = datetime.strptime(tf, &quot;%H:%M:%S&quot;)
     delta_time = current_time - last_calltime
  
  if abs(delta_time.total_seconds()) &gt;= 3:
      if &quot;Red&quot; in cube:
          last_color = &quot;Red&quot;
      elif &quot;Green&quot; in cube:
          last_color = &quot;Green&quot;
      else:
          last_color = &quot;Blue&quot;
  
      t = time.localtime()
      tf = time.strftime(&quot;%H:%M:%S&quot;,t)
      last_calltime = datetime.strptime(tf, &quot;%H:%M:%S&quot;)
  
      return last_color
  
  
  
  if __name__ == '__main__':
  
  try:
      rospy.init_node('color')
      rospy.Subscriber ('/topic',String, callback)
      rospy.spin()
  </code></pre>
  <p>In another file, I need to reference this &quot;last_color&quot; variable that updates. So far the function I have in this file:</p>
  <pre><code>from color import last_color
      
      a = 0
  
      def observe_color(a)
         if a == 0:
           return last_color 
         else: 
           return &quot;None&quot;
  </code></pre>
  <p>I need this to return the updated variable from the &quot;color.py&quot; file but it only returns the initialized value for last_color which is &quot;&quot;. How can I do this?</p>