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


Groups > comp.lang.python > #11135

Re: how to dynamically generate __name__ for an object?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@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; 'subject:object': 0.07; 'python': 0.08; '>>>>': 0.09; '__name__': 0.09; 'descriptor': 0.09; 'am,': 0.12; 'def': 0.15; '(instance': 0.16; '@property': 0.16; 'descriptor,': 0.16; 'instances.': 0.16; 'cc:addr:python- list': 0.16; 'wrote:': 0.16; 'wed,': 0.17; '>>>': 0.18; 'cc:no real name:2**0': 0.20; 'seems': 0.20; 'cc:2**0': 0.22; 'header:In- Reply-To:1': 0.22; 'aug': 0.24; 'classes': 0.28; 'message- id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'example': 0.30; 'class': 0.30; 'subject:?': 0.31; 'received:209.85.161.46': 0.31; 'received:mail-fx0-f46.google.com': 0.31; '...': 0.34; 'uses': 0.35; 'received:209.85.161': 0.35; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'property': 0.63; "'foo'": 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=hmuVjRQIPyQ2UCo1ESxDncblu1JOnFrKQbG6MnOQpn4=; b=nGun3ALCr3lNCqh3ttKXiANtn3EBP7wjMf7RmaLuV2dy0qWg3YW9X/YP8PoNiu9Pd1 /GbaQJa4MqsXz4C5jEX7dSEIEXYzqpIFO/p1Aeer40otOeVqff6paX9ojioUsIcCOZBS /DpjjkK1dqb0yGdHqZKGpvHXY3lhZItEoMqA4=
MIME-Version 1.0
In-Reply-To <afb6fca6-126a-44cf-8ef6-ba29c8f2ef93@r12g2000vbe.googlegroups.com>
References <mailman.2004.1312686417.1164.python-list@python.org> <afb6fca6-126a-44cf-8ef6-ba29c8f2ef93@r12g2000vbe.googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 10 Aug 2011 09:25:08 -0600
Subject Re: how to dynamically generate __name__ for an object?
To Fuzzyman <fuzzyman@gmail.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.12
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.2117.1312989942.1164.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1312989942 news.xs4all.nl 23846 [2001:888:2000:d::a6]:45409
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11135

Show key headers only | View raw


On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman <fuzzyman@gmail.com> wrote:
> __name__ can be a descriptor, so you just need to write a descriptor
> that can be fetched from classes as well as instances.
>
> Here's an example with a property (instance only):
>
>>>> class Foo(object):
> ...   @property
> ...   def __name__(self):
> ...     return 'bar'
> ...
>>>> Foo().__name__
> 'bar'

But:

>>> Foo.__name__
'Foo'
>>> repr(Foo())
'<__main__.Foo object at 0x00CAFFD0>'
>>> Foo.__dict__['__name__']
<property object at 0x00CBA6F0>

It seems that Foo.__name__ and Foo.__dict__['__name__'] are not the
same thing, and Python itself only uses the former.

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


Thread

how to dynamically generate __name__ for an object? Eric Snow <ericsnowcurrently@gmail.com> - 2011-08-06 21:06 -0600
  Re: how to dynamically generate __name__ for an object? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-07 14:47 +1000
    Re: how to dynamically generate __name__ for an object? Eric Snow <ericsnowcurrently@gmail.com> - 2011-08-07 02:05 -0600
  Re: how to dynamically generate __name__ for an object? Fuzzyman <fuzzyman@gmail.com> - 2011-08-10 07:48 -0700
    Re: how to dynamically generate __name__ for an object? Ian Kelly <ian.g.kelly@gmail.com> - 2011-08-10 09:25 -0600
      Re: how to dynamically generate __name__ for an object? Fuzzyman <fuzzyman@gmail.com> - 2011-08-10 09:38 -0700
    Re: how to dynamically generate __name__ for an object? Eric Snow <ericsnowcurrently@gmail.com> - 2011-08-10 10:54 -0600

csiph-web