News for hackers. Stuff that matters.
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

    for name, age, title in cursor.fetchall():
        print(name, age, title)
Ofcourse you have to come up with different variable names, but it still seems more elegant to just unpack.
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
Re:Lesser known parts of Python standard library – Trickster... by sgarland on Friday September 06, 2024 @07:44AM (#41465243)
By default, List[Tuple]]. You could do a list comp over the fetchall(), but at that point there’s already some magic happening, so why not make it explicit?