Get a list of field values from Python's sqlite3, not tuples representing rows

后端 未结 8 979
我在风中等你
我在风中等你 2020-12-12 17:31

It\'s annoying how Python\'s sqlite3 module always returns a list of tuples! When I am querying a single column, I would prefer to get a plain list.

e.g. when I exec

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 17:47

    You don't really want to do this - anything you do along the lines of using zip or a list comprehension is just eating CPU cycles and sucking memory without adding significant value. You are far better served just dealing with the tuples.

    As for why it returns tuples, it's because that is what the Python DBD API 2.0 requires from fetchall.

提交回复
热议问题