How to iterate through the columns in a row using sqlite3.Row

Chris Green cl at isbd.net
Mon Mar 13 04:42:22 EDT 2017


Paul Rubin <no.email at nospam.invalid> wrote:
> Chris Green <cl at isbd.net> writes:
> >         self.conn = sqlite3.connect(dbname)
> >         self.conn.row_factory = sqlite3.Row
> >         self.cursor = self.conn.cursor()
> >         self.table = table
> >         ...
> >         ...
> >         sql = "SELECT * FROM " + self.table + " WHERE firstName||lastName = ?"
> >         self.cursor.execute(sql, (name,))
> >         row = self.cursor.fetchone()
> 
> untested:
> 
> with sqlite3.connect(dbname) as conn:
>    sql = "SELECT * FROM " + self.table + " WHERE firstName||lastName = ?"
>    cursor = conn.execute(sql, (name,))
>    row = cursor.fetchone()

Ay?  I've maybe not explained well.

I want to iterate through row *after* the above code such that I can
see the column names as 'keys' and the corresponding values.

-- 
Chris Green
·



More information about the Python-list mailing list