raspberry pi - python error in main method defenetion -
this first python code , trying connect data base , think connection part processed
import mysqldb class database: host = "localhost" user = "root" passwd = "root" db = "pitest" def __init__(self): self.connection = mysqldb.connect( host = self.host, user = self.user, passwd = self.passwd, db = self.db) def query(self, q): cursor = self.connection.cursor( mysqldb.cursors.dictcursor ) cursor.execute(q) return cursor.fetchall() def __del__(self): self.connection.close() if __name__ == "__main__": db = database() q = "delete users" db.query(q) q = """ insert users (title, fname, sname, age, email) values ('a', 'z', 'big z', '20', 'raspberrypi@example.com'), ('b', 'x', 'big x', '30', 'raspberrypi@example.com'), ('c', 'y', 'big y', '24', 'raspberrypi@example.com'), ('a', 'w', 'big w', '29', 'raspberrypi@example.com') """
every time try run code error:
file "mysqlconnection.py", line 26 if __name__ == "__main__": ^
can 1 me please
it indentation error.
if __name__ == '__main__':
is not in same indentation level
def __del__(self):
please fix it. think hitting backspace once before if block do.
Comments
Post a Comment