0

I'm brand new to classes in python, I have my function to call tweets based on a keyword and analyze their sentiment values. Here is the class code:

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")

Here is where I am calling the class(don't know if I'm doing this right, I'm new to python and programming in general):

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

When I run the code in the terminal it reads:

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

I've done some searching and I haven't found anything that works, I'm a bit stumped! Thank You! For some reason, I can't get the code for the beginning of the class to paste at the top so here it is:

    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)
  • `myfuncs` is not a function, it's a class. So before calling the `searchForKeyword` method of the class you need to create a instance of the class: `m = myfuncs(...)`. – Yassine Faris May 24 '18 at 14:06
  • Possible duplicate of [Python Unbound Method TypeError](https://stackoverflow.com/questions/6012799/python-unbound-method-typeerror) – Yassine Faris May 24 '18 at 14:06
  • Thank You, I realized my class is really poorly designed, fixed most of the errors including misspellings. – Season5Ryze May 24 '18 at 14:14

0 Answers0