【发布时间】:2016-06-01 12:19:19
【问题描述】:
我正在尝试在 twython 中扩展一个类 TwythonStreamer。跟随: [Inheritance and Overriding __init__ in python。重新定义工作正常的 on_success 方法。我的问题是添加一个计数变量并将其初始化为零。我收到错误“TypeError:init() 只需要 1 个参数(给定 5 个)”,因为我搞砸了 init()。
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__需要为您传递的所有内容(加上self)提供一个参数。您尚未在其签名中添加任何参数。