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


Groups > comp.lang.python > #35601

Re: Finding the name of a function while defining it

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'explicitly': 0.04; 'function,': 0.07; 'object)': 0.09; 'pep': 0.09; 'similar,': 0.09; 'subject:while': 0.09; 'url:peps': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'dec': 0.15; 'naming': 0.16; 'rejected.': 0.16; 'string': 0.17; 'wrote:': 0.17; 'url:dev': 0.17; 'email addr:gmail.com&gt;': 0.20; 'cc:2**0': 0.23; '&gt;': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'name?': 0.29; 'function': 0.30; 'url:python': 0.32; 'defining': 0.33; 'like:': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'url:org': 0.36; 'possible': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'here': 0.65; 'sender:addr:chris': 0.84; 'abc': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=z85h2nr25TNqxcwQAA72d7zufDjF35n4r6AleDgqeLs=; b=ellc5y9CNeYmp+EDEJdYwvwvCaExc+Q/1CXu6SnbnMP6b6fAx0RP3iwZQen1Hw82cg eZRFh3wrQ+gV9GlgXTeT38CUovrhQy6yhH16ASo/QtHM/nsmdiTjG3eEgKXDE024XTwz B1OiGzbCqSNvEJWv9bVKP8JiBzUkLcWDqGW4E=
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=z85h2nr25TNqxcwQAA72d7zufDjF35n4r6AleDgqeLs=; b=Q7LmqMgBvRfhQ3yzk+i8Z9YStk5St535GSbkIqe9+J9i8rsYPep4cdRRRrVxHH7MND D8496n9rJS5vXN+ooWIEhKixBFnQYwTy4+RxsAIDWngGXFJzHPX2tQPa+NrWnDSVjdgX daWYsctCfnKEz67yQiuKxrS9/z/lduDITNWRWFG85ql72HzzbkROLSxLg1qnHv9zQ7xl R+xzAYd0jb+ao6cL3wLfyrdpMyicffR/E8GI5fEllMlIHoAhtVoSROeGyOqCnrQdMhCw QcSDpb47LgHsOZcRHtYUNtAEdzBq73dVbiW9VYZBubGxxvFV/5HJ2pt86GTGD6UIAJBR opHg==
MIME-Version 1.0
Sender chris@rebertia.com
In-Reply-To <c9548d77-ccc3-4b47-b84b-9a9f0c2852ce@googlegroups.com>
References <c9548d77-ccc3-4b47-b84b-9a9f0c2852ce@googlegroups.com>
Date Thu, 27 Dec 2012 00:26:24 -0800
X-Google-Sender-Auth pJObByJrAJwNdA8IbeBAHY9cNxk
Subject Re: Finding the name of a function while defining it
From Chris Rebert <clp2@rebertia.com>
To Abhas Bhattacharya <abhasbhattacharya2@gmail.com>
Content-Type multipart/alternative; boundary=14dae934103b7040c904d1d14d81
X-Gm-Message-State ALoCoQm5+78UOz1GRLgTDu9gxJS2R/8gw6dAOTBIoxCoMPTliITZHXS090gVvlHq+VGbt3ntw7J4
Cc Python <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1335.1356597235.29569.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1356597235 news.xs4all.nl 6866 [2001:888:2000:d::a6]:57918
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:35601

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Dec 25, 2012 6:06 PM, "Abhas Bhattacharya" <abhasbhattacharya2@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.

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