Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '*args,': 0.07; '**kwargs)': 0.09; '**kwargs):': 0.09; 'subject:while': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'dec': 0.15; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'function?': 0.16; 'lambda': 0.16; 'message- id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'wed,': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'beauty': 0.22; 'object.': 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; '>>>>': 0.29; "d'aprano": 0.29; 'steven': 0.29; "i'm": 0.29; 'function': 0.30; 'code': 0.31; 'similar': 0.35; 'there': 0.35; 'possible': 0.37; 'one,': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'where': 0.40; 'different': 0.63; 'afraid': 0.66; 'madness': 0.84; 'received:50.22': 0.84 Date: Thu, 27 Dec 2012 07:32:16 -0600 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16 MIME-Version: 1.0 To: Steven D'Aprano Subject: Re: Finding the name of a function while defining it References: <0kknd8tbg7knqa1ng6igbj8u82mqb720oi@4ax.com> <50dc29e9$0$29967$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <50dc29e9$0$29967$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com 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: , Newsgroups: comp.lang.python Message-ID: Lines: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356615069 news.xs4all.nl 6941 [2001:888:2000:d::a6]:37983 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35621 On 12/27/12 04:58, Steven D'Aprano wrote: > On Wed, 26 Dec 2012 23:46:31 -0800, Abhas Bhattacharya wrote: > >>>> two = lamba : "one" >>>> one = two >>> >>>> Which one of these is the "name" of the function? > [...] >> If i call one() and two() respectively, i would like to see "one" and >> "two". > > I'm afraid you're going to be disappointed. There is no possible way for > one() and two() as shown above to report different names, because they > are the same function object. > > py> two = lambda : "one" > py> one = two > py> one is two > True > py> one, two > ( at 0xb7abd92c>, at 0xb7abd92c>) And for similar fun: def call(fn, *args, **kwargs): return fn(*args, **kwargs) two = lambda : "one" one = two print(call(two)) print(call(one)) Depending on where in the code you are, the same function object also has a local name of "fn". It's madness until you understand it, and then it's beauty :) -tkc