之前我进行db select,只有一个field的时候,代码有点不大优雅:
cursor.execute("select max(id) from mytable")
id = cursor.fetchone()[0]
现在发现一个比较优雅一点的方法:
id, = cursor.fetchone()
如果用fetchall(),则可以如下:
result_tupel = cursor.fetchall()
for id, in result_tuple:
...
之前我进行db select,只有一个field的时候,代码有点不大优雅:
cursor.execute("select max(id) from mytable")
id = cursor.fetchone()[0]
现在发现一个比较优雅一点的方法:
id, = cursor.fetchone()
如果用fetchall(),则可以如下:
result_tupel = cursor.fetchall()
for id, in result_tuple:
...