I wrote the following example:
class Demo:
def __init__(self,value):
self._value = value
def _getValue(self):
print "_getValue"
return self._value
value = property(_getValue,None,None,"DocString")
a = Demo(10)
print a.value
a.value = 15
print a.value
and the output is:
_getValue
10
15
Why can I still set 'value'? Is it possible at all to make it read-only or
do I have to write a funktion _setValue(self,value) which raises an
exception?
regards,
Achim
You have to make Demo a subclass of some new-style class for properties
to work right. Old-style classes do not go well with properties, e.g.
something like
class Demos(object):
<whatever>
is enough.
>
>regards,
>Achim
>
With my best regards,
G. Rodrigues
Laura Creighton