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