我收到了消息: 你的程序中有一个错误:期望一个缩进的块 在这里第4行,打印数据。
class listener(StreamListener):
def on_data(self, data):
try:
print data
saveFile = open('UkmDB','a')
saveFile.write(data)
saveFile.write('\n')
saveFile.close()
return True
except BaseException, e:
print 'failed ondata,',str(e)
time.sleep(5)
答案 0 :(得分:1)
try:
之后你需要缩进:
class listener(StreamListener):
def on_data(self, data):
try:
print data
saveFile = open('UkmDB','a')
saveFile.write(data)
saveFile.write('\n')
saveFile.close()
return True
except BaseException, e:
print 'failed ondata,',str(e)
time.sleep(5)
答案 1 :(得分:0)
class listener(StreamListener):
def on_data(self, data):
try:
print data
saveFile = open('UkmDB','a')
saveFile.write(data)
saveFile.write('\n')
saveFile.close()
return True
except BaseException, e:
print 'failed ondata,',str(e)
time.sleep(5)