Quantcast
Viewing all articles
Browse latest Browse all 4852

Python • Re: RRDtool & python3 code optimization

This code gets hometemp and temp in one python script. twotemps.py:

Code:

#!/usr/bin/python3import mysql.connectormydb = mysql.connector.connect(  host="localhost",  database="exampledb",  user="pi",  passwd="password")mycursor = mydb.cursor()sql = "select hometemp,temp from outsidetemp where id = (select max(id)-1 from outsidetemp)"mycursor.execute(sql)data = mycursor.fetchone()hometemp = data[0]temp = data[1]mycursor.close()mydb.close()print(hometemp,temp)
Thanks! I`ll try your solution. I was thinking that fetchone() is for one value, but it`s for one row Image may be NSFW.
Clik here to view.
:)
Thanks again.

Statistics: Posted by independent — Sat Aug 10, 2024 2:10 pm



Viewing all articles
Browse latest Browse all 4852

Trending Articles