property and virtuality

boisgera Sebastien.Boisgerault at gmail.com
Fri Apr 1 12:00:02 EST 2005


Laszlo Zsolt Nagy <gandalf at geochemsource.com> wrote in message news:<mailman.1128.1112268435.1799.python-list at python.org>...
> My problem is about properties and the virtuality of the methods. I 
> would like to create a property whose get and set methods
> are virtual. I had the same problems in Delphi before and the solution 
> was the same. I created a private _get method and a public
> get method. The former one will call the latter. 
> [...]
> I cannot override C2._getname instead, because c2.name would print 
> 'Test2" instead of lala. Clearly, the property stores a reference to the 
> get and set methods and it is not possible to have it use the new 
> methods.  Creating a new property is the worst - need to duplicate code 
> and also C3.name is C1.name returns False. :-) It is not a big problem 
> because I found the solution just I wonder if there is a better way to 
> "virtualize" property get/set functions.

Alex Martelli has demonstrated the same technique to "fix" this
disturbing property behavior during one of its talk at Pycon 2005:

http://www.python.org/pycon/2005/papers/36/ (slides p.7&8)

... from this I infer that you found the best fix available ;)

Regards,

Sébastien



More information about the Python-list mailing list