Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'attribute': 0.05; '__name__': 0.07; 'function,': 0.07; '*is*': 0.09; 'subject:while': 0.09; 'to:addr:comp.lang.python': 0.09; 'unnamed': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'dec': 0.15; "function's": 0.16; 'function).': 0.16; 'function?': 0.16; 'wrote:': 0.17; 'exists': 0.17; 'thu,': 0.17; 'creates': 0.18; 'tim': 0.18; 'names.': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; 'compiled': 0.27; 'object,': 0.27; "doesn't": 0.28; 'chris': 0.28; 'peer': 0.29; 'that.': 0.30; 'thursday,': 0.30; 'function': 0.30; 'expect': 0.31; 'code': 0.31; 'december': 0.32; 'received:google.com': 0.34; 'whatever': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'method': 0.36; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'received:209.85.214': 0.39; 'think': 0.40; 'more': 0.63; 'grab': 0.64; 'presumably': 0.84 Newsgroups: comp.lang.python Date: Wed, 26 Dec 2012 23:46:31 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=117.194.200.146; posting-account=4mdDiQoAAAB1VBViHzAN7cTcuXiGgMWL References: <0kknd8tbg7knqa1ng6igbj8u82mqb720oi@4ax.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 117.194.200.146 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 Cc: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 60 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356594400 news.xs4all.nl 6951 [2001:888:2000:d::a6]:49398 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35590 On Thursday, 27 December 2012 11:14:36 UTC+5:30, Chris Angelico wrote: > On Thu, Dec 27, 2012 at 3:52 PM, Tim Roberts wrote: > > > The > > > compiled code in a function, for example, exists as an object without a > > > name. That unnamed object can be bound to one or more function names, but > > > the code doesn't know that. Example: > > > > > > def one(): > > > print( "Here's one" ) > > > > > > two = one > > > > > > That creates one function object, bound to two names. What name would you > > > expect to grab inside the function? > > > > Presumably 'one'. > > > > > Even more obscure: > > > > > > two = lamba : "one" > > > one = two > > > > > > Which one of these is the "name" of the function? > > > > I would say ''. Whatever method is used to get the function's > > name, I would expect it to match the __name__ attribute of the > > function (which is a peer to __code__, but I don't think the > > function's code *is* the function). > > > > ChrisA If i call one() and two() respectively, i would like to see "one" and "two".