On 17Nov2013 13:47, Tim Chase <python.l...@tim.thechases.com> wrote:
> On 2013-11-17 11:34, Ned Batchelder wrote:
> > Functions have a __name__ attribute, which is the name they were
> > defined as:
> > 
> >     >>> def foo(): pass  
> >     ...
> >     >>> foo.__name__  
> >     'foo'
> >     >>> bar = foo
> >     >>> bar.__name__  
> >     'foo'
> 
> which they have even in less-than-useful situations:
> 
>   (lambda s: s.lower()).__name__
> 
> accurately returns that its name is "<lambda>".  So you get what you
> pay for ;-)

Also, it is documented that you may assign to __name__.

I've started doing that in a few cases where I have a table of lambdas mapped
by operation names; I've started labelling the lambdas to get better debugging.
-- 
Cameron Simpson <c...@zip.com.au>

Ride with a llama and you never ride alone.
        - Jeff Earls, DoD #0530, <jea...@tekig6.pen.tek.com>
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to