使用tweepy调用python类时的Unbound方法

时间:2018-05-24 13:55:48

标签: python twitter tweepy

我是python中的新手,我的功能是根据关键字调用推文并分析他们的情绪值。这是类代码:

def searchForKeyword(self, x, z):
    a = []
    s = 0
    public_tweets = api.search(x, count = z)
    for tweet in public_tweets:
        analysis = TextBlob(tweet.text)
        a.append(s)
        a[s] = analysis.sentiment
        print(a[s])
        s = s + 1
        print("succesful")

这是我在调用类的地方(不知道我是否正确这样做,我是python和编程的新手):

import tweepy
from textblob import TextBlob
from myfuncs import myfuncs as m
m.searchForKeyword('capitals', 50)

当我在终端中运行代码时,它会显示:

    unbound method searchForKeyword() must be called with myfuncs instance as first argument (got str instance instead)

我已经做了一些搜索,我没有找到任何有用的东西,我有点难过!谢谢! 出于某种原因,我无法将类的开头的代码粘贴到顶部,所以这里是:

    import tweepy
    from textblob import TextBlob
    class myfuncs:
        def __init__(self, consumer_key, consumer_secret, access_token, access_toekn_secret, auth, api):
        self.consumer_key = 'ur7LPai7hD8nYw9CMlQ8exgEO'
        self.consumer_secret = 'mak7uBwYNucDIhF4lPIfy4JMIEIaVM9Dx0zgEo2LYwru7UDHPi'
        self.access_token = '816453418235600896-jvDVIfnewq6oJzYIbDFh7vvI9vfMd2I'
        self.access_token_secret = 'kqJFFHCJMA1mWQmg2XFPvFSnRGasxx4CgxhNVY3vZIweh'
        self.auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
        self.api = tweepy.API(auth)

0 个答案:

没有答案