pythonfetchall

Python fetchall return true and false


I have a python script that makes a 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()

My problem is that the cursor.fetchall() is returning True or Falses (and others columns with others values example above) but in the database the value is a bit 1 or 0 and when exported to CSV it puts the True or False and I want 1 or 0.

Sample data returned in SQL:

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

Solution

  • You can use int()

    Ex:

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

    Output:

    1
    0