properties and formatting with self.__dict__
Alex Martelli
aleax at aleax.it
Fri Feb 21 14:56:40 EST 2003
<posted & mailed>
Andrew Bennetts wrote:
...
>> > You should write in the __init__ method something like
>> >
>> > "self.full_name=property(self.get_full_name)"
...
>> Except that, unfortunately, properties won't work as instance
>> attributes,
>> only as class attributes.
>
> I think you could fairly easily write your own instanceproperty that did
> work with instances, though.
Could you? Maybe I'm having a blind spot, but, without having a
custom metaclass (redefining __getattribute__ differently from the
implementation in object), how would you do it? I.e. how would you
code a type instanceproperty such that:
class UIP(object):
def getfullname(self): return 'Monty Python'
def __init__(self):
self.fulname = instanceproperty(self.getfullname)
x = UIP()
print x.fullname
would result in x.getfullname() being _called_? I just can't
see how, and I'd like to learn -- thanks!
Alex
More information about the Python-list
mailing list