Re: iterating over DictRow

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: David Raymond <David(dot)Raymond(at)tomtom(dot)com>, "psycopg(at)lists(dot)postgresql(dot)org" <psycopg(at)lists(dot)postgresql(dot)org>
Subject: Re: iterating over DictRow
Date: 2020-09-24 15:51:52
Message-ID: 7b2272a8-de4d-bc95-1efc-84d69ea7c4c1@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On 9/24/20 7:53 AM, David Raymond wrote:
> 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():
> ...
>

Except I think the_dict is actually the_list. I was just about to post a
reply to my post saying that my use of the_dict was incorrect as I was
actually iterating over a list.

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse psycopg by date

  From Date Subject
Next Message Karsten Hilbert 2020-09-24 21:11:47 Re: iterating over DictRow
Previous Message David Raymond 2020-09-24 14:53:40 RE: iterating over DictRow