I'm new to python,
I have this error:
Error :
def on_data(self,data):
^
IdentationError : unindent does not match any outer indentation level
I am code from notepad++v windows 8.1. I don’t understand why I have this error, I paid attention to the tabs and space.
I want to save data in self.file
Here is my code:
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
from tweepy import Stream
import tweepy
import time
class StdOutListener(StreamListener):
def __init__(self,file):
self.file = file
def on_data(self, data):
print data
self.file.write(data)
return True
def on_error(self, status):
print status
def main() :
file = open('work.txt','w')
listn = StdOutListener(file)
consumer_key=""
consumer_secret=""
access_token=""
access_token_secret=""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, listn)
stream.filter(track=['lol'])
file.close()
source
share