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

时间:2015-12-21 21:02:25

标签: python tweepy

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

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)

1 个答案:

答案 0 :(得分:12)

在行中:

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

你试图致电streamListener,因为你已经在那里找到了parens。相反,只需传递对象本身,即:

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