[英]Python how to return a list to other functions?
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?命令应该是“返回 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
在每个函数中,您必须添加如下内容: twitchClipLinks = api()
或者您可以将twitchClipLinks
定义为global variable
并从api()
函数中删除return
语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.