Python fetchall return 真假

Python fetchall return true and false

我有一个 python 脚本可以生成 fetchall():

connection = pymssql.connect(host='host', user='user', password='pw', database='database', as_dict=True)

cursor = connection.cursor()

cursor.execute("EXEC SPname")
data=cursor.fetchall()

我的问题是 cursor.fetchall() 正在返回 True 或 Falses(以及上面带有其他值示例的其他列)但在数据库中该值有点 1 或 0,当导出到 CSV 时它输入 True 或 False,我想要 1 或 0。

SQL中返回的示例数据:

ID      Price       Price2      Price3      Active      Opened      Sent        Enable
1      12234.09     1111.09    3444.36      1           1           1           0   

您可以使用int()

例如:

print(int(True))
print(int(False))

输出:

1
0

fetchall returns 元组或字典列表。将它们转换为整数的最简单方法是将 int 方法映射到该列表:

data_in_integer_form = map(int, data)