Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #11135
| 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 | 2011-08-10 09:25 -0600 |
| Subject | Re: how to dynamically generate __name__ for an object? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2117.1312989942.1164.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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