Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35579

Re: Finding the name of a function while defining it

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 <rosuav@gmail.com>
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 <c9548d77-ccc3-4b47-b84b-9a9f0c2852ce@googlegroups.com> <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 <rosuav@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1323.1356587079.29569.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Thu, Dec 27, 2012 at 3:52 PM, Tim Roberts <timr@probo.com> 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 '<lambda>'. 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-25 18:00 -0800
  Re: Finding the name of a function while defining it Roy Smith <roy@panix.com> - 2012-12-25 22:11 -0500
    Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:26 -0800
      Re: Finding the name of a function while defining it Chris Angelico <rosuav@gmail.com> - 2012-12-27 18:48 +1100
        Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:52 -0800
        Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:52 -0800
    Re: Finding the name of a function while defining it Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-27 12:59 +0000
  Re: Finding the name of a function while defining it Tim Roberts <timr@probo.com> - 2012-12-26 20:52 -0800
    Re: Finding the name of a function while defining it Chris Angelico <rosuav@gmail.com> - 2012-12-27 16:44 +1100
      Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:46 -0800
        Re: Finding the name of a function while defining it Chris Angelico <rosuav@gmail.com> - 2012-12-27 18:52 +1100
          Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:55 -0800
          Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:55 -0800
      Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:46 -0800
        Re: Finding the name of a function while defining it Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-27 10:58 +0000
          Re: Finding the name of a function while defining it Tim Chase <python.list@tim.thechases.com> - 2012-12-27 07:32 -0600
            Re: Finding the name of a function while defining it Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-27 13:34 +0000
          Re: Finding the name of a function while defining it Roy Smith <roy@panix.com> - 2012-12-27 10:09 -0500
            Re: Finding the name of a function while defining it Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-28 01:07 +0000
    Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-26 23:45 -0800
      Re: Finding the name of a function while defining it Mitya Sirenef <msirenef@lightbird.net> - 2012-12-27 03:03 -0500
        Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-27 00:26 -0800
          Re: Finding the name of a function while defining it Mitya Sirenef <msirenef@lightbird.net> - 2012-12-27 04:07 -0500
        Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-27 00:26 -0800
      Re: Finding the name of a function while defining it Chris Rebert <clp2@rebertia.com> - 2012-12-27 00:58 -0800
      Re: Finding the name of a function while defining it Tim Roberts <timr@probo.com> - 2012-12-28 21:01 -0800
      Re: Finding the name of a function while defining it Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-12-29 12:18 +0200
  Re: Finding the name of a function while defining it Chris Rebert <clp2@rebertia.com> - 2012-12-27 00:26 -0800
    Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-27 00:42 -0800
    Re: Finding the name of a function while defining it Abhas Bhattacharya <abhasbhattacharya2@gmail.com> - 2012-12-27 00:42 -0800
  Re: Finding the name of a function while defining it Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-27 13:31 +0000
    Re: Finding the name of a function while defining it alex23 <wuwei23@gmail.com> - 2012-12-27 17:25 -0800

csiph-web