Python read from txt and save into mysql

Next step is simple:

from contextlib import closing

with closing(self.db.cursor()) as cur:
    cur.execute("INSERT INTO table1(`measured_at`,`temp`) VALUES(%s, %s)", (measured_at,  temp))
    self.db.commit()

P.S. It looks like you ask this question because you didn’t make your homework and didn’t read via ANY python tutorial how to work with MySQL.

Leave a Comment