I'm a little confused on this particular problem and I have had this trouble for quite sometime now. The problem is that I don't know how to properly add a new class variable to an already defined class. In my scenario, I am using the tweepy module and using its Streaming API in order to get twitter messages that contain 'lol' in them.
Here is the code so far:
import tweepy
class StreamListener(tweepy.StreamListener):
#I want to add some code here in order to open a file
def on_status(self, status):
try:
#Rather than printing here I would like to write to the file
print status.text
except:
self.textOut.close()
auth1 = tweepy.auth.OAuthHandler(XXXXX, XXXX)
auth1.set_access_token(XXXXX, XXXXX)
api = tweepy.API(auth1)
textOut = open('twitterMessages.txt')
l = StreamListener()
streamer = tweepy.Stream(auth=auth1, listener=l, timeout=3000000000 )
setTerms = ['lol', 'Lol', 'LOL']
streamer.filter(None,setTerms)
Look at the comments I made. I want to open a file to begin with and write to the file. The problem is when I create an init method, it seems to override the original init method.