我正在为 python 制作一个 twitch.tv API 包装器,当我运行以下代码时,print (t.getstatus)
它会打印 :<bound method twitchchannel.getstatus of <__main__.twitchchannel instance at 0x0198D3A0>>
而不是变量的值。我究竟做错了什么?
import urllib2
import json
class twitchchannel():
def __init__ (self,channel):
self.channel = channel
url = 'https://api.twitch.tv/kraken/channels/' + channel
dict1 = json.loads(urllib2.urlopen(url).read())
self.status = dict1 ['status']
self.display_name = dict1 ['display_name']
self.mature = dict1 ['mature']
self.chanurl = dict1 ['url']
self.created_at = dict1 ['created_at']
self.teams = dict1 ['teams']
self.game = dict1 ['game']
self.updated_at = dict1 ['updated_at']
print dict1
def getstatus(self):
return self.status
t = twitchchannel('ethotv')
print (t.getstatus)
print (t.status) #This works