title: Flask/Python - passing variables between functions
body: <p>I've spent a few days looking at this on and off but I can't work out what I'm doing wrong.  I've tried to follow this:</p>
  
  <p><a href="https://stackoverflow.com/questions/16043797/python-passing-variables-between-functions">Passing Variables between functions</a></p>
  
  <p>I'm still not clear on what I need to do though.</p>
  
  <p>This is what I have presently but I've tried various permutations:</p>
  
  <pre><code>def root():
          hivelogin()
          occupancy()
          print (hiveSessionId)
          return ("Done")
  </code></pre>
  
  <p>I need this to work in lots of places but I'll use hivelogin() as the example:</p>
  
  <pre><code>def hivelogin():
          import requests
          url = "https://api.prod.bgchprod.info:443/omnia/auth/sessions"
          payload = "{\n    \"sessions\": [{\n        \"username\": \"xxxxxxxxxxx\",\n        \"password\": \"xxxxxxxxxxx\",\n        \"caller\": \"WEB\"\n    }]\n}"
          headers = {
              'Content-Type': "application/vnd.alertme.zoo-6.1+json",
              'Accept': "application/vnd.alertme.zoo-6.1+json",
              'X-Omnia-Client': "Hive Web Dashboard",
              'Cache-Control': "no-cache",
              }
  
          response = requests.request("POST", url, data=payload, headers=headers)
          data=response.json()
          hiveSessionId = (data['sessions'][0]['sessionId'])
          session['hiveSessionId'] = (data['sessions'][0]['sessionId'])
          return hiveSessionId
  </code></pre>
  
  <p>I've got round it by using a session variable in this case but I don't want to have to do this when I've probably got loads of variables I need to pass around.</p>
  
  <p>So, what I need is for hiveSessionId to my root (or any other) function.</p>
  
  <p>If I do:</p>
  
  <pre><code>def root(hiveSessionId=None)
  </code></pre>
  
  <p>I get nothing - as I'd expect.</p>
  
  <p>If I do:</p>
  
  <pre><code>def root(hiveSessionId=hiveSessionId)
  </code></pre>
  
  <p>I get an error - as I'd expect.</p>
  
  <p>So, the simple question is how I pass a variable from the function that creates it to any other function in my app - probably between routes as I'm using Flask but I'm using MySQL to give some persistence.</p>
  
  <p>I've done a tiny bit of coding in the past with PHP but please bear in mind that I'm old, been learning Python for about 3 weeks, and this is my first app.  I did the "Hello world" thing, watched a video about Python on Youtube and then did this so it's probably going to make you want to cry.</p>
  
  <p>EDIT: Simplified pseudo version of what I want:</p>
  
  <pre><code>def a():
      b()
      return x
  
  def b():
      x=10
  </code></pre>