1

I have been trying to return the list so other functions can access it. But in all the other functions the variables become undefined. The command should be "return twitchClipLinks" right?

def api():
  #API via twitch to get the top clips of Just Chatting
  API_ENDPOINT = 'https://api.twitch.tv/kraken/clips/top?game=Just%20Chatting&period=day&trending=false&limit=6'
  ID = 'REMOVED'
  auth = 'application/vnd.twitchtv.v5+json'

  head = {
    'Client-ID' : ID,
    'Accept' : auth
  }

  r = requests.get(url = API_ENDPOINT, headers = head)

  twitchClipLinks = []
  data = r.json()

  for link in data['clips']:
    store = str(link['url'])
    twitchClipLinks.append(store)
  return twitchClipLinks
3
  • 1
    What do you mean by the variables become unsolved? Commented Nov 2, 2020 at 6:53
  • I got 5 other def that uses the twitchClipLinks. I get the error Undefined variable: 'twitchClipLinks' Commented Nov 2, 2020 at 7:00
  • 1
    Did u call this function from those functions? And did u assign the result to any variable? Inside every function, you have to add something like this: twitchClipLinks = api() Or you can define twitchClipLinks as a global variable and remove the return statement from ur api() function Commented Nov 2, 2020 at 7:02

1 Answer 1

1

Inside every function, you have to add something like this: twitchClipLinks = api() Or you can define twitchClipLinks as a global variable and remove the return statement from ur api() function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.