Python mysql connector returns tuple

后端 未结 2 1704
陌清茗
陌清茗 2021-01-18 17:26

I am connecting to mysql database via mysql connector and running a simple query to pull a list of IDs. I need to loop over that list and pass them into some other code. For

2条回答
  •  甜味超标
    2021-01-18 18:15

    Yes, this is expected behavior. Using the cursor as an iterable is basically equivalent to looping over it using the fetchone() method. From the documentation for fetchone() (emphasis mine):

    This method retrieves the next row of a query result set and returns a single sequence, or None if no more rows are available. By default, the returned tuple consists of data returned by the MySQL server, converted to Python objects. If the cursor is a raw cursor, no such conversion occurs;

提交回复
热议问题