properties and formatting with self.__dict__

Andrew Bennetts andrew-pythonlist at puzzling.org
Wed Feb 19 19:02:04 EST 2003


On Wed, Feb 19, 2003 at 03:51:40PM -0500, Jp Calderone wrote:
> On Wed, Feb 19, 2003 at 12:05:41PM -0800, Michele Simionato wrote:
> > [snip]
> > 
> > The problem is that writing "full_name = property(get_full_name)" in
> > the class scope, as you do, put "full_name" in the class dictionary, 
> > not in the instance dictionary (this is the standard behaviour).
> > You should write in the __init__ method something like
> > 
> > "self.full_name=property(self.get_full_name)"
> > 
> > This will give you as output
> > 
> > <Person first=mark last=mceahern full=<property object at 0x8108a7c>
> > 
> > and from there you should be able yourself to figure out where to go ;)
> > 
> 
>   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.

-Andrew.






More information about the Python-list mailing list