title: Python return values from one function to another in infinite loop
body: <p>Problem:</p>
  
  <p>def tradingview(): is infite loop which should return two numbers</p>
  
  <pre><code>def tradingview():
          while True:           
                  with open(filepath, 'r') as f:
                          count_var_short = f.read().count('Exit Short    Open')
                          print('Current shorts open:',count_var_short)                            
                  with open(filepath, 'r') as f:
                          count_var_long = f.read().count('Exit Long    Open')
                          print('Current longs open:',count_var_long)                           
          return (count_var_short,count_var_long)
  
  
  def target_balance(count_var_short,count_var_long):
          current_target = cur_price_VWAP['vwap'] * freebalance['BTC']['free']
          print ('current_target long',current_target * count_var_short)
          print ('current_target short',current_target * count_var_long)
  
  if __name__ == '__main__':
          Thread(target = tradingview).start()
          Thread(target = target_balance(count_var_short,count_var_long)).start()
  </code></pre>
  
  <p>This code gives error </p>
  
  <pre><code>Thread(target = target_balance(count_var_short,count_var_long)).start()
  NameError: name 'count_var_short' is not defined
  </code></pre>
  
  <p>===============================================</p>
  
  <p>i want <code>def tradingview():</code>   return two numbers</p>
  
  <p><code>count_var_short</code> and <code>count_var_long</code></p>
  
  <p>and use them in function </p>
  
  <pre><code>def target_balance(count_var_short,count_var_long):
  </code></pre>
  
  <p>i know i should read how return works, but i will very thankful if someone help me on my own code because it is much more understandable for me.</p>