I am trying to take the variable generated from cpu usage, but for some reason and no matter what I try the terminal returns a syntax error after getCpuLoad)) and also the sqlite3 query doesn't effect the table or database in question.
def main():
while True:
print"CPU usage=%.2f%%" % (getCpuLoad()*100)
cursor.execute("INSERT INTO mytable (Date, Cpu) VALUES (?,?)", (today, getCpuLoad))
time.sleep(INTERVAL)
conn.commit()
conn.close()
can someone please help?
Martijn Pieters
1.1m326 gold badges4.2k silver badges3.5k bronze badges
1 Answer 1
You are trying to insert the function, not it's result. Call the function again:
cursor.execute("INSERT INTO mytable (Date, Cpu) VALUES (?,?)", (today, getCpuLoad()))
If today is a function as well, you'd need to call that too of course.
answered Mar 14, 2013 at 12:13
Martijn Pieters
1.1m326 gold badges4.2k silver badges3.5k bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
user2169708
so do i have to call the function to retrieve the results printed from getCpuLoad for insertion into the database or are you saying don't call the function if i want to insert the result of the function
Martijn Pieters
@user2169708: You have to call a function to insert the results of the function.
default