Python子类Callb中的计数器

2024-10-01 07:27:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用TwythonStream计算,并试图得到一个计数的例子,一个部分刺痛被发现。下面的代码运行,但每个实例的计数器保持为1。作为一个Python NOOB,任何帮助或建议都是值得的

from twython import TwythonStreamer

class myStream(TwythonStreamer):

    def on_success(self, data):

        if 'text' in data:
            counter = counter + 1
            print("found %d" % counter)
        if counter == 3:
            print("Found three!")
            self.disconnect()

Tags: 实例fromselfdataifcounter计数器建议