Re: how to dynamically generate __name__ for an object?

2011-08-10 Thread Fuzzyman
On Aug 7, 4:06 am, Eric Snow ericsnowcurren...@gmail.com 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: # module base.py class _NameProxy(object):     def __init__(self, oldname):         self.oldname =

Re: how to dynamically generate __name__ for an object?

2011-08-10 Thread Ian Kelly
On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman fuzzy...@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

Re: how to dynamically generate __name__ for an object?

2011-08-10 Thread Fuzzyman
On Aug 10, 4:25 pm, Ian Kelly ian.g.ke...@gmail.com wrote: On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman fuzzy...@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

Re: how to dynamically generate __name__ for an object?

2011-08-10 Thread Eric Snow
On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman fuzzy...@gmail.com wrote: On Aug 7, 4:06 am, Eric Snow ericsnowcurren...@gmail.com 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: # module base.py class

Re: how to dynamically generate __name__ for an object?

2011-08-07 Thread Eric Snow
On Sat, Aug 6, 2011 at 10:47 PM, Steven D'Aprano steve+comp.lang.pyt...@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

how to dynamically generate __name__ for an object?

2011-08-06 Thread Eric Snow
Thought I knew how to provide a dynamic __name__ on instances of a class. My first try was to use a non-data descriptor: # module base.py class _NameProxy(object): def __init__(self, oldname): self.oldname = oldname def __get__(self, obj, cls): if obj is None:

Re: how to dynamically generate __name__ for an object?

2011-08-06 Thread Steven D'Aprano
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?