我是一個初學者在python
,Python的IndentationError取消縮進不匹配任何外部縮進級別
我有這樣的錯誤:
Error :
def on_data(self,data):
^
IdentationError : unindent does not match any outer indentation level
與windows 8.1
notepad++
我的代碼。我不明白爲什麼我有這個錯誤,我關注了標籤和空間。
我想將數據保存在self.file
這裏是我的代碼:
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()
Martijn,你怎麼知道OP代碼中使用了哪些空格? (我在帖子中看到的都是空格。) – 2014-11-03 18:47:21
@ ron.rothman:你打開編輯器並檢查源代碼中是否有跳轉選項。 – 2014-11-03 18:48:29
啊,我明白了。謝謝! – 2014-11-03 18:50:49