title: UnboundLocalError: local variable 'url' referenced before assignment
body: <p>I'm trying to get this code working, but it keeps coming up with the error in the title. I don't get it. The function "url" is set before the "get_media" function, and the same function call thing works with other functions I've set, but it says otherwise. I've looked at similar question's answers, but I cannot understand any of them, because the answers are designed around their complicated code, and they offer up no proper explanation as to how it works.</p>
  
  <pre><code>def url(path):
      if path.find("?") != -1:
          pre = "&amp;"
      else:
          pre = "?"
      return protocol +"://" +host +base_path +path +pre +"access_token=" +access_token
  
  def get_media(insta_id, max_id=None):
      insta_id = str(insta_id)
      path = url("/users/%s/media/recent/") # ERROR COMES UP HERE
      if max_id is not None:
          path = path +"&amp;max_id=%s" % max_id
      url = urllib.request.urlopen(path)
      url = url.read().decode("utf-8")
      url = json.loads(url)
      return url
  </code></pre>
  
  <p>Any help appreciated. Tell me if you need more code to work with. </p>
  
  <p>B</p>