0

I'm trying to extend a class, TwythonStreamer in twython. Followed: [Inheritance and Overriding __init__ in python. Redefining the on_success method which works fine. My problem is adding a count variable and initializing it to zero. I get the error "TypeError: init() takes exactly 1 argument (5 given)" because I'm messing up the 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")
Community
  • 1
  • 1
Jim Smith
  • 457
  • 5
  • 9
  • Your `__init__` needs a parameter for everything you're passing (plus self). You haven't added any parameters to its signature. – Gerrat Feb 19 '16 at 19:41

1 Answers1

1

I solved my issue by adding after I created stream:

stream.count = 0

and deleting my init

Now in the object I can use self.count. This works but is at best inelegant.

Jim Smith
  • 457
  • 5
  • 9