Readonly attributes ...

kobayashi kobayashi at
Mon Mar 29 11:33:33 CEST 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
    def getX(self):
        return self.__x
    def setX(self, value):
        self.__x = value
    x = property(getX, setX)

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 !



More information about the Python-list mailing list