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; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'dec': 0.15; 'function).': 0.16; 'string': 0.17; 'wrote:': 0.17; 'thu,': 0.17; 'module': 0.19; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; '(which': 0.26; 'chris': 0.28; 'run': 0.28; 'thursday,': 0.30; 'function': 0.30; 'december': 0.32; 'function.': 0.33; 'that,': 0.34; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'itself': 0.37; 'ok,': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'called': 0.39; 'skip:" 10': 0.40; 'your': 0.60; 'kind': 0.61; 'acts': 0.71; '(yes,': 0.84 Newsgroups: comp.lang.python Date: Wed, 26 Dec 2012 23:52:22 -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: <9ca1c0f1-fd79-4525-a571-64f1efb2eefa@googlegroups.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 Content-Transfer-Encoding: quoted-printable 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356594753 news.xs4all.nl 6954 [2001:888:2000:d::a6]:54893 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35594 On Thursday, 27 December 2012 13:18:19 UTC+5:30, Chris Angelico wrote: > On Thu, Dec 27, 2012 at 6:26 PM, Abhas Bhattacharya >=20 > wrote: >=20 > > During run-time, I can always use: function_name.__name__ (although tha= t's kind of lame because it returns "function_name"). But if the function i= tself contains print(__name__) and I call the function, it returns __main__= (yes, __main__ itself, not the string "__main__") (which is the calling fu= nction). >=20 >=20 >=20 > That's because __name__ looks for that attribute on the module (aka >=20 > "global variable"), not the function. When you run your Python script >=20 > as an application, the module is called __main__. >=20 >=20 >=20 > ChrisA Ok, that sheds some light on why it acts like that, but how can i use it th= e way I want (which i already told)?