Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59817 > unrolled thread

Re: Obtaining "the" name of a function/method

Started byCameron Simpson <cs@zip.com.au>
First post2013-11-18 11:19 +1100
Last post2013-11-18 11:19 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Obtaining "the" name of a function/method Cameron Simpson <cs@zip.com.au> - 2013-11-18 11:19 +1100

#59817 — Re: Obtaining "the" name of a function/method

FromCameron Simpson <cs@zip.com.au>
Date2013-11-18 11:19 +1100
SubjectRe: Obtaining "the" name of a function/method
Message-ID<mailman.2810.1384733986.18130.python-list@python.org>
On 17Nov2013 13:47, Tim Chase <python.list@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 <cs@zip.com.au>

Ride with a llama and you never ride alone.
        - Jeff Earls, DoD #0530, <jearls@tekig6.pen.tek.com>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web