property decorator and inheritance
OKB (not okblacke)
brenNOSPAMbarn at NObrenSPAMbarn.net
Fri Nov 11 00:54:50 EST 2011
Laurent wrote:
> Yes using a separate class variable would transfer the problem to
> the class level. But adding 10 class variables if I have 10
> properties would be ugly. Maybe I should reformulate the subject of
> this thread to "is there some python magic to pass parameters to
> decorator-declared properties ?"
You can't have it both ways. If you want
myObj.greeting2 # No parentheses
To evaluate to a string (which it will if it's a property as you
set it up), then it is necessarily true that myObj.greeting2(somearg) is
going to try to call that string, which isn't going to work. If you
need to be able to pass in parameters, then you need greeting2 to be a
real method, not a property, and you need to get the greeting string
with
myObj.greeting2() # Parentheses
All this is as it should be. The whole point of properties is that
outside functions accessing them don't "know" that a getter function is
called behind the scenes.
--
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
--author unknown
More information about the Python-list
mailing list