Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #11002
| References | <mailman.2004.1312686417.1164.python-list@python.org> <4e3e18ee$0$29985$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| Date | 2011-08-07 02:05 -0600 |
| Subject | Re: how to dynamically generate __name__ for an object? |
| From | Eric Snow <ericsnowcurrently@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2007.1312704349.1164.python-list@python.org> (permalink) |
On Sat, Aug 6, 2011 at 10:47 PM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > Eric Snow wrote: > >> Thought I knew how to provide a dynamic __name__ on instances of a >> class. My first try was to use a non-data descriptor: > > Perhaps you should explain what you are trying to do. If you want to give > instances their own name, why not just give them an instance > attribute "name"? Double-leading-and-trailing-underscore attributes are > reserved for Python, and have special semantics. Again useful information failed to make it from my head to the keyboard. :) Currently I am looking at objects, regardless of their types, and keying off their name. If it is a module, class, or function object, the name should be stored in __name__ already. If it is an instance of the Base class I demonstrated, I would like to maintain that convention. However, you may have a good point. In other code I can simply check for the name attribute I choose for my objects and also check for __name__. I suppose I just liked the idea of having a single attribute to check. -eric > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list >
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