我有一个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()
Run Code Online (Sandbox Code Playgroud)
我的问题是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
Run Code Online (Sandbox Code Playgroud)
您可以使用 int()
例如:
print(int(True))
print(int(False))
Run Code Online (Sandbox Code Playgroud)
输出:
1
0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
137 次 |
| 最近记录: |