2
我想從一張表中取出一條記錄並將其放入變量「gl」中。 如果值則值偏大或偏小+ -GL應該寫入到數據庫python&Mysql:不支持的操作數類型爲 - :'int'和'元組'
import MySQLdb
import time
import string
while True:
db = MySQLdb.connect(host="10.0.0.100", port=3306, user="ubuntu", passwd="ubuntu", db="test")
cursor = db.cursor()
cursor.execute("SELECT glaettung FROM ttable ORDER BY id DESC LIMIT 1")
gl = cursor.fetchall()
print gl
value = (20)
if (value < (value-gl)):
cursor = db.cursor()
cursor.execute("INSERT INTO ttable (value) VALUES(%s)", (value))
elif (value > (value+gl)):
cursor = db.cursor()
cursor.execute("INSERT INTO ttable (value) VALUES(%s)", (value))
else:
print "Done"
這是錯誤:
[email protected]:~/Dokumente$ python test.py
(('2',),)
Traceback (most recent call last):
File "test.py", line 13, in <module>
if (value < (value-gl)):
TypeError: unsupported operand type(s) for -: 'int' and 'tuple'
謝謝,thas是問題!現在它可以工作:-) – Schnickschnackschabernack