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


Groups > comp.lang.python > #35603

Re: Finding the name of a function while defining it

Newsgroups comp.lang.python
Date 2012-12-27 00:42 -0800
References <c9548d77-ccc3-4b47-b84b-9a9f0c2852ce@googlegroups.com> <mailman.1335.1356597235.29569.python-list@python.org>
Subject Re: Finding the name of a function while defining it
From Abhas Bhattacharya <abhasbhattacharya2@gmail.com>
Message-ID <mailman.1336.1356598346.29569.python-list@python.org> (permalink)

Show all headers | View raw


On Thursday, 27 December 2012 13:56:24 UTC+5:30, Chris Rebert  wrote:
> On Dec 25, 2012 6:06 PM, "Abhas Bhattacharya" <abhasbhat...@gmail.com> wrote:
> 
> >
> 
> > While I am defining a function, how can I access the name (separately as string as well as object) of the function without explicitly naming it(hard-coding the name)?
> 
> > For eg. I am writing like:
> 
> > def abc():
> 
> >     #how do i access the function abc here without hard-coding the name?
> 
> Not possible per se without resorting to sys._getframe() or similar hackery.
> 
> A simple+elegant way to do this would require PEP 3130 (http://www.python.org/dev/peps/pep-3130/ ) or similar, but that particular proposal got rejected.

Thanks for telling that. I thought that there is a direct way, and now you have confirmed that there isn't. So, as I can see, Mitya's code can be a perfect way-around, although it will require another function.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-25 18:00 -0800
  Re: Finding the name of a function while defining it Roy Smith <roy@panix.com> - 2012-12-25 22:11 -0500
    Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:26 -0800
      Re: Finding the name of a function while defining it Chris Angelico <rosuav@gmail.com> - 2012-12-27 18:48 +1100
        Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:52 -0800
        Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:52 -0800
    Re: Finding the name of a function while defining it Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-27 12:59 +0000
  Re: Finding the name of a function while defining it Tim Roberts <timr@probo.com> - 2012-12-26 20:52 -0800
    Re: Finding the name of a function while defining it Chris Angelico <rosuav@gmail.com> - 2012-12-27 16:44 +1100
      Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:46 -0800
        Re: Finding the name of a function while defining it Chris Angelico <rosuav@gmail.com> - 2012-12-27 18:52 +1100
          Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:55 -0800
          Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:55 -0800
      Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:46 -0800
        Re: Finding the name of a function while defining it Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-27 10:58 +0000
          Re: Finding the name of a function while defining it Tim Chase <python.list@tim.thechases.com> - 2012-12-27 07:32 -0600
            Re: Finding the name of a function while defining it Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-27 13:34 +0000
          Re: Finding the name of a function while defining it Roy Smith <roy@panix.com> - 2012-12-27 10:09 -0500
            Re: Finding the name of a function while defining it Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-28 01:07 +0000
    Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:45 -0800
      Re: Finding the name of a function while defining it Mitya Sirenef <msirenef@lightbird.net> - 2012-12-27 03:03 -0500
        Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-27 00:26 -0800
          Re: Finding the name of a function while defining it Mitya Sirenef <msirenef@lightbird.net> - 2012-12-27 04:07 -0500
        Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-27 00:26 -0800
      Re: Finding the name of a function while defining it Chris Rebert <clp2@rebertia.com> - 2012-12-27 00:58 -0800
      Re: Finding the name of a function while defining it Tim Roberts <timr@probo.com> - 2012-12-28 21:01 -0800
      Re: Finding the name of a function while defining it Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-12-29 12:18 +0200
  Re: Finding the name of a function while defining it Chris Rebert <clp2@rebertia.com> - 2012-12-27 00:26 -0800
    Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-27 00:42 -0800
    Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-27 00:42 -0800
  Re: Finding the name of a function while defining it Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-27 13:31 +0000
    Re: Finding the name of a function while defining it alex23 <wuwei23@gmail.com> - 2012-12-27 17:25 -0800

csiph-web