0

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
asked Mar 14, 2013 at 12:11

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

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
@user2169708: You have to call a function to insert the results of the function.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.