Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #59817
| Date | 2013-11-18 11:19 +1100 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: Obtaining "the" name of a function/method |
| References | <20131117134726.5fef18ca@bigbox.christie.dr> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2810.1384733986.18130.python-list@python.org> (permalink) |
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>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Obtaining "the" name of a function/method Cameron Simpson <cs@zip.com.au> - 2013-11-18 11:19 +1100
csiph-web