错误代码:
from tweepy.streaming import StreamListener
class StdOutListener(StreamListener):
# class StdOutListener(Listener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
print(data)
return True
- 改正方法:对类的引入要准确
将:
from tweepy.streaming import StreamListener
改为:
from tweepy.streaming import sream, StreamListener
正确代码:
from tweepy.streaming import Stream,StreamListener
class StdOutListener(StreamListener):
# class StdOutListener(Listener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
print(data)
return True
- 还有一种情况是在class定义中的继承不准确,参考以下例子:
unittest报错解决方法:是因为继承错了。testHttp应该继承unittest.TestCase
第二个例子来源于:https://blog.csdn.net/qq_41751871/article/details/113878641