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: 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: References: From: Ian Kelly Date: Wed, 10 Aug 2011 09:25:08 -0600 Subject: Re: how to dynamically generate __name__ for an object? To: Fuzzyman 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman 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): > ... =A0 @property > ... =A0 def __name__(self): > ... =A0 =A0 return 'bar' > ... >>>> Foo().__name__ > 'bar' But: >>> Foo.__name__ 'Foo' >>> repr(Foo()) '<__main__.Foo object at 0x00CAFFD0>' >>> Foo.__dict__['__name__'] It seems that Foo.__name__ and Foo.__dict__['__name__'] are not the same thing, and Python itself only uses the former.