RE: iterating over DictRow

From: David Raymond <David(dot)Raymond(at)tomtom(dot)com>
To: "psycopg(at)lists(dot)postgresql(dot)org" <psycopg(at)lists(dot)postgresql(dot)org>
Subject: RE: iterating over DictRow
Date: 2020-09-24 14:53:40
Message-ID: AM0PR07MB4036EA8B58205084F30DA2AC87390@AM0PR07MB4036.eurprd07.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Since DictRow's can be indexed by either the field name or the field index (either record["ID"] or record[0]) then I think what it "should" be is a little ambiguous. But you can always either cast it to a dict, or iterate over .keys() if you want the field names.

for field in dict(the_dict):
...
or
for field in the_dict.keys():
...

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Adrian Klaver 2020-09-24 15:51:52 Re: iterating over DictRow
Previous Message Adrian Klaver 2020-09-23 23:54:44 Re: iterating over DictRow