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; 'example:': 0.03; 'attribute': 0.05; '__name__': 0.07; 'function,': 0.07; '*is*': 0.09; 'subject:while': 0.09; 'unnamed': 0.09; 'def': 0.10; 'dec': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; "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; 'header:In-Reply-To:1': 0.25; '(which': 0.26; 'compiled': 0.27; 'object,': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'peer': 0.29; 'that.': 0.30; 'function': 0.30; 'expect': 0.31; 'code': 0.31; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'whatever': 0.35; 'pm,': 0.35; 'received:209.85.220': 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; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'more': 0.63; 'grab': 0.64; 'presumably': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=jgknCyMqMYLDkVTCgrhl4OOgsLyybvGY9p4y4litbj4=; b=yWzdDeBPhu74Nd+7NIimEuVsnIbkDlovCRj1ATxfWm8sF2JJdJ/99ZIalOjDe/O75C f5GlX3Go2OWsJ5U2kc6XZBvhtU1y1y6KvTF632dQBX7MkUdbKnByZ7GxpvMT7Lm34YXD rGoE0E581odcLD5XSG6DE+4QicpVjOXCswmgfNNm8uyxJyIUdwSyRdyBE6sxUTIo69M/ /GzAxTIpKvI9x7GCVVLSQQIhUN2WnmxTYMFClMrKcialIMrjxWJKDjsZ/F+cZxUVBjif dYY3gs1ORZWN5Xly1xIgUC13dBjdqjwGnJ2u8m5FYsGvWwoxKGGIYZeHKEFbrvBI21Rm P2nA== MIME-Version: 1.0 In-Reply-To: <0kknd8tbg7knqa1ng6igbj8u82mqb720oi@4ax.com> References: <0kknd8tbg7knqa1ng6igbj8u82mqb720oi@4ax.com> Date: Thu, 27 Dec 2012 16:44:36 +1100 Subject: Re: Finding the name of a function while defining it From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356587079 news.xs4all.nl 6934 [2001:888:2000:d::a6]:49499 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35579 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