[PyGreSQL] Re: DictCursor support for 3.8.1

D'Arcy J.M. Cain darcy at PyGreSQL.org
Tue Sep 19 13:20:56 EDT 2006


On Tue, 19 Sep 2006 09:49:22 +0200
Simon Pamies <s.pamies at banality.de> wrote:
> > Also, I will probably remove the lambda function and just make it a
> > simple method.
> 
> If I may ask: Why? For this usecase the lambda function is clean and
> simple :-)

To some extent I just want to stay away from the poltics.  Search the
web to see the controversy over lambda.  Besides, I do find the second
line below clearer than the first.

self.row_factory = lambda cur, row: row
def row_factory(cur, row): return row

In fact, let's make your comment a docstring:

def row_factory(cur, row):
    """you can overwrite this with a custom row factory
       e.g. a dict_factory

       cursor = pgdbCursor(src, cache)
       def cursor.row_factory(caller, row):
           d = {}
           for idx, col in enumerate(caller.description):
               d[col[0]] = row[idx]
           return d
    """
    return row


-- 
D'Arcy J.M. Cain
PyGreSQL Development Group
http://www.PyGreSQL.org


More information about the PyGreSQL mailing list