Lambda returning tuple question, multi-expression

Chris Angelico rosuav at gmail.com
Thu Mar 9 06:27:11 EST 2023


On Thu, 9 Mar 2023 at 09:14, aapost <aapost at idontexist.club> wrote:
>
> When making a UI there are a lot of binding/trace operations that need
> to occur that lead to a lot of annoying 1 use function definitions. I
> don't really see lambda use like below.
>
> Giving 2 working lambda examples using a returned tuple to accomplish
> multiple expressions - what sort of gotchas, if any, might make the
> following bad practice if I am missing something?

IMO there's nothing wrong with this, but it's worth considering a few
alternatives. For instance, the single-use function might be less
annoying if you don't have to also name the function in the
constructor; this could be achieved with proper use of a decorator, or
possibly use of a class namespace, with an appropriate helper. But
otherwise, this tuple trick seems pretty much fine to me, although
you're still restricted to a series of expressions (no statements), so
your code is still going to get a bit awkward if it does anything
complicated.

ChrisA


More information about the Python-list mailing list