module attributes and docstrings

Chris Angelico rosuav at gmail.com
Tue Mar 24 06:29:44 EDT 2015


On Tue, Mar 24, 2015 at 7:55 PM, Mario Figueiredo <marfig at gmail.com> wrote:
> So things like the one below are something I got used to do, but that
> don't work after all, as I learned today:
>
>     value_factory = lambda _, row: row[0]
>     """Row factory. To be used with single-column queries."""
>
> There are other things I could possibly do, like turning that lambda
> into a function, or document attributes in the module docstring. They
> are fair responses.

They certainly are. Any time you assign a lambda function directly to
a simple name, it's probably worth replacing with a def function:

def value_factory(_, row):
    """Row factory. To be used with single-column queries."""
    return row[0]

(Though I'd be inclined to give the first parameter a proper name here)

ChrisA



More information about the Python-list mailing list