Re:Lesser known parts of Python standard library – Trickster...
by wodenokoto on Thursday September 05, 2024 @12:39PM
(#41458284)
I'm not quite sure how the fetchall() return type looks, but couldn't you just
Ofcourse you have to come up with different variable names, but it still seems more elegant to just unpack.
[ Parent
| on HN ]
Re:Lesser known parts of Python standard library – Trickster...
by Joker_vD on Thursday September 05, 2024 @01:25PM
(#41458703)
Honestly, the "proper" way should be passing something like this
def namedtuple_factory(cursor, row):
fields = [column[0] for column in cursor.description]
cls = namedtuple("Row", fields)
return cls._make(row)
to the fetchall(), to automatically keep the names in sync with those in the SQL query string.
Re:Lesser known parts of Python standard library – Trickster...
by ttyprintk on Friday September 06, 2024 @07:11AM
(#41465022)
Implemented as conn.row_factory = sqlite3.Row