mardi 19 juillet 2016

Python error when I want to print

This code works perfectly:

class MyStreamer(TwythonStreamer):
def on_success(self, data): 
    txt=json.dumps(data)
    #print txt
    cur2 = cnx.cursor()
    sql="INSERT INTO TWTemp(TWTempTXT,TWTempEstadoCdg) VALUES('"+txt+"',0)"
    cur2.execute(sql)
    cnx.commit()
    self.disconnect()

def on_error(self, status_code, data):
    print status_code, data
    self.disconnect()

but when line 4 ("print txt") is uncommented, I see the following error:

File "tw.py", line 13
print txt
^
IndentationError: unexpected indent

Somebody help me? Regards Bruno

3 commentaires: