module attributes and docstrings

Terry Reedy tjreedy at udel.edu
Tue Mar 24 15:33:41 EDT 2015


On 3/24/2015 4:55 AM, Mario Figueiredo wrote:
> Reading PEP 257 and 258 I got the impression that I could document
> module attributes and these would be available in the __doc__
> attribute of the object.
>
> 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,

You have discovered one of advantages of a def statement over a 
name=lambda assignment statement.  In Python, there is no good reason to 
use the latter form and PEP 8 specifically discourages it: "Always use a 
def statement instead of an assignment statement that binds a lambda 
expression directly to an identifier."

-- 
Terry Jan Reedy




More information about the Python-list mailing list