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