类型错误 'class' 对象不可调用

type error 'class' object not callable

我有一个 class MyStreamListener,我想从另一个文件调用它,但我得到了 type error 'MyStreamListener' not callable。根据我在引用用户制作的 classes 时所读到的内容,可能是因为我试图访问 python 中的保留关键字,但我已经尝试更改 [=] 的名称28=]。我还有什么地方做错了吗?

functionality.py

from authenticate import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
from twitter_stream import MyStreamListener

def oauth_authenticate():
        auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
        auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
        api = tweepy.API(auth)

        return api

def streaming():
        api = oauth_authenticate()
        streamListener = MyStreamListener()

        stream = tweepy.Stream(auth=api.auth, listener=streamListener())

if __name__ == '__main__':
        print "wanting to stream"
        streaming()
        print "EXITING"

twitter_stream.py

import tweepy

class MyStreamListener(tweepy.StreamListener):

        def on_status(self, status):
                print(status.text)

行中:

stream = tweepy.Stream(auth = api.auth, listener = streamListener())

您正在尝试呼叫 streamListener,因为那里有 parens。相反,只需传递 object 本身,即:

stream = tweepy.Stream(auth=api.auth, listener=streamListener)