Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'to:addr:comp.lang.python': 0.09; 'url:peps': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'dec': 0.15; "isn't.": 0.16; 'naming': 0.16; 'rejected.': 0.16; 'string': 0.17; 'wrote:': 0.17; 'url:dev': 0.17; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'cc:addr:gmail.com': 0.27; 'see,': 0.27; 'received:209.85.212': 0.28; 'chris': 0.28; 'name?': 0.29; 'that.': 0.30; 'thursday,': 0.30; 'function': 0.30; 'code': 0.31; 'december': 0.32; 'url:python': 0.32; 'defining': 0.33; 'function.': 0.33; 'like:': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'confirmed': 0.35; 'so,': 0.35; 'pm,': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'url:org': 0.36; 'possible': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'telling': 0.61; 'perfect': 0.63; 'here': 0.65; 'direct': 0.69; 'abc': 0.91 Newsgroups: comp.lang.python Date: Thu, 27 Dec 2012 00:42:19 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=117.194.202.165; posting-account=4mdDiQoAAAB1VBViHzAN7cTcuXiGgMWL References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 117.194.202.165 MIME-Version: 1.0 Subject: Re: Finding the name of a function while defining it From: Abhas Bhattacharya To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Python , Abhas Bhattacharya X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356598346 news.xs4all.nl 6886 [2001:888:2000:d::a6]:35395 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35603 On Thursday, 27 December 2012 13:56:24 UTC+5:30, Chris Rebert wrote: > On Dec 25, 2012 6:06 PM, "Abhas Bhattacharya" wr= ote: >=20 > > >=20 > > While I am defining a function, how can I access the name (separately a= s string as well as object) of the function without explicitly naming it(ha= rd-coding the name)? >=20 > > For eg. I am writing like: >=20 > > def abc(): >=20 > > =A0 =A0 #how do i access the function abc here without hard-coding the = name? >=20 > Not possible per se without resorting to sys._getframe() or similar hacke= ry. >=20 > 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 reje= cted. 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 pe= rfect way-around, although it will require another function.