Skip to content Skip to sidebar Skip to footer

Mysql Returned Datatype And Python Outputs Different Type For Different Functions

I am having plenty of problems with the MySQL returns and entering it into a Qt table with python. I use data = cursor.fetchall() for data in data: for i in range(len(data)):

Solution 1:

You cannot change the data from the fetchall method since it is a tuple and not a list. The easiest fix would be to do:

data = [list(i) for i in cursor.fetchall()]

Solution 2:

From your error log, I think problem happens because tuple in python doesn't support assignment.

Return values you fetch are ready-only tuple so it's invalid to change value directly on that.

In your code :

    data[i] = data[i].strftime("%Y-%m-%d %H:%M:%S")

Do you want to revise original data stored in DB directly? If not, you could use another variable with list type, like:

    my_list = data[i].strftime("%Y-%m-%d %H:%M:%S")
    // TODO MORE

Otherwise you may rely on update sentence to reivse data in DB.

Post a Comment for "Mysql Returned Datatype And Python Outputs Different Type For Different Functions"