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; 'attribute': 0.05; '__name__': 0.07; 'function,': 0.07; 'python': 0.09; '(aka': 0.09; '(although': 0.09; 'itself,': 0.09; 'subject:while': 0.09; 'dec': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function).': 0.16; 'string': 0.17; 'wrote:': 0.17; 'thu,': 0.17; 'module': 0.19; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; '(which': 0.26; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'run': 0.28; 'function': 0.30; 'function.': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'itself': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'kind': 0.61; '(yes,': 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:content-transfer-encoding; bh=q32/UCncFTEknd9eMIsijd+whZZWQvu7Fkqfhxoy8r0=; b=Sp8WAhSSOk8lsVlmrXs3M5anvo5EnyZuRuC5ttra30OWDLBiiL8sYr3OOcRzbjnl2g xo7HfEKgEN+EewXEJKmZsgtAP4dBzYTitfqktXUB2hNn7bOzS9vB1ICKlJa0ZCnKc8Lq Sk4UyU0BwNuKF3RNtnFrFGvI9c5RgHlLXr3xLYcVDkbUnuxK/qwEmcnNv5Zp9RpQ0SN/ izePlr4vEwim/kfVCb08mNIXl33i4xYx7QidaGIAA1ouZPNstHlPP0GTecWTV7nuKTQZ sjtm23iqCy6qLbXs7SUX1dRD31CWohdZXtQnT1lMQxRosPfxfbYc7a2Xm+oo1vdBJzyT YFEg== MIME-Version: 1.0 In-Reply-To: <9ca1c0f1-fd79-4525-a571-64f1efb2eefa@googlegroups.com> References: <9ca1c0f1-fd79-4525-a571-64f1efb2eefa@googlegroups.com> Date: Thu, 27 Dec 2012 18:48:19 +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 Content-Transfer-Encoding: quoted-printable 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: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356594507 news.xs4all.nl 6868 [2001:888:2000:d::a6]:50582 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35591 On Thu, Dec 27, 2012 at 6:26 PM, Abhas Bhattacharya wrote: > During run-time, I can always use: function_name.__name__ (although that'= s kind of lame because it returns "function_name"). But if the function its= elf contains print(__name__) and I call the function, it returns __main__ (= yes, __main__ itself, not the string "__main__") (which is the calling func= tion). That's because __name__ looks for that attribute on the module (aka "global variable"), not the function. When you run your Python script as an application, the module is called __main__. ChrisA