Python如何将列表返回其他功能?

时间:2020-11-02 06:52:01

标签: python python-3.x string list return

我一直试图返回列表,以便其他功能可以访问它。但是在所有其他函数中,变量变得不确定。命令应该是“ return twitchClipLinks”吧?

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

1 个答案:

答案 0 :(得分:1)

在每个函数中,您必须添加以下内容:twitchClipLinks = api()或可以将twitchClipLinks定义为global variable并从您的{{1 }}功能。

相关问题