I am new to python. I have a few questions coming from an armature!

Chris Angelico rosuav at gmail.com
Thu Aug 18 07:44:27 EDT 2016


On Thu, Aug 18, 2016 at 7:32 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> So I don't see any
> benefit over this:
>
>          for section_name, line_number in text.parser.toc:
>              drop.add_command(label=section_name, command=lambda
>                               line=line_number: text.yview(line))
>
> except that it is easier to fit in 79 columns :-)

Which is a VERY important benefit when you realize what's just
happened to your code. Wrapping after "command=lambda" and before
"line=linenumber" majorly obscures what's going on here. Here's a
better way to wrap that:

         for section_name, line_number in text.parser.toc:
             drop.add_command(label=section_name,
                    command=lambda line=line_number: text.yview(line))

However, this isn't an indictment of lambda, just proof that anyone
can misalign stuff by mistake.

ChrisA



More information about the Python-list mailing list