Making the case for "typed" lists/iterators in python

Chris Angelico rosuav at gmail.com
Fri Dec 16 13:25:12 EST 2011


On Sat, Dec 17, 2011 at 5:05 AM, Roy Smith <roy at panix.com> wrote:
> Most of this was TL:DNR, but I will admit I often wish for a better way
> to log intermediate values.  For example, a common pattern in the code
> I'm working with now is functions that end in:
>
>   return [Foo(x) for x in bunch_of_x_thingies]
>
> When something goes amiss and I want to debug the problem, I often
> transform that into:
>
>    temp = [Foo(x) for x in bunch_of_x_thingies]
>    logger.debug(temp)
>    return temp
>
> It would be convenient to be able to get at and log the intermediate
> value without having to pull it out to an explicit temporary.

tee = lambda func,arg: (func(arg),arg)[1]

return tee(logger.debug,[Foo(x) for x in bunch_of_x_thingies])

ChrisA



More information about the Python-list mailing list