Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I'm a beginner in python,

I have this error :

Error :

def on_data(self,data): 

IdentationError: unindent does not match any outer indentation level

I code with notepad++ in windows 8.1. I don't understand why I have this error, I have paid attention to 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) 

#api = tweepy.API(auth)

#filename=open('helloworld.txt','r')

#f=filename.readlines() 

#filename.close() 

#for line in f: 

# api.update_status(line) 

stream = Stream(auth, listn)

stream.filter(track=['lol']) 

file.close()

1 Answer

0 votes
by (106k points)

Here is a screenshot of your code in my text editor; I set the tab stop to 8 spaces (which is what Python users) and selected the text, which causes the editor to display tabs with continuous horizontal lines:

highlighted code with tabs shown as lines

Related questions

0 votes
1 answer
0 votes
1 answer
asked Mar 23, 2021 in Python by Rekha (2.2k points)
0 votes
1 answer
asked Apr 26, 2020 in Python by Sudhir_1997 (55.6k points)

Browse Categories

...