Readonly attributes ...
kobayashi
kobayashi at netcourrier.com
Mon Mar 29 04:33:33 EST 2004
Hi all python users,
A question about readonly attributes once again, but
even reading the threads about "properties" and "descriptors",
I can't find exactly what I want.
Let a developper to write the class
class A(object):
def __init__(self):
self.x = 1
self.setX(2)
return
def getX(self):
return self.__x
def setX(self, value):
self.__x = value
return
x = property(getX, setX)
pass
Of course, the developper can set the attribute 'x'
in the class ...
Now, the user part :
a = A()
print a.x
a.x = 1 # I want this operation to raise
print a.x
a.setX(23) # I want this operation to raise too !!
print a.getX()
I can't find a way to do that ... but may be I've
missed something !
Cheers,
K.
More information about the Python-list
mailing list