0
我想在twython中扩展一个类TwythonStreamer。跟随: [Inheritance and Overriding __init__ in python。重新定义可以正常工作的on_success方法。我的问题是添加一个计数变量并将其初始化为零。我得到错误“TypeError:init()只需要1个参数(给出5)”因为我搞砸了初始化()。twython继承变量
from twython import TwythonStreamer
C_KEY = "my_key"
C_SECRET = ""
A_TOKEN = ""
A_SECRET = ""
class MyStreamer(TwythonStreamer):
def __init__(self):
super(MyStreamer, self).__init__()
self.count = 0
def on_success(self, data):
if 'text' in data:
self.count += 1
print("found it.", self.count)
stream = MyStreamer(C_KEY, C_SECRET, A_TOKEN, A_SECRET)
stream.statuses.filter(track="Primary")
你的'__init__'需要你传递的所有参数(加上自己)。您尚未为其签名添加任何参数。 – Gerrat