【发布时间】:2019-05-15 02:10:16
【问题描述】:
我有一个返回元组的查询,我试图将第一个值从该元组转换为 int,但它总是给我这个错误:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'tuple'
我不明白为什么要这样做,因为返回的值看起来像这样:[(25,)]
代码如下:
cursor.execute("SELECT temp FROM temperatures WHERE datetimetest = ?", [datenow])
currentTemp = cursor.fetchall()
print(currentTemp) # this gives me [(25,)]
convertedTemp = int(currentTemp[0])
【问题讨论】:
-
[(25,)]是一个列表,其中包含一个 int 的元组(1 个长度的元组)。不要尝试转换,只需使用var[0][0]访问它
标签: python sql type-conversion