About classes and OOP in Python

danmcleran at yahoo.com danmcleran at yahoo.com
Mon Apr 10 10:58:45 EDT 2006


You can do this in Python as well. Check out the property built-in
function. One can declare a property with a get, set, and delete
method. Here's a small example of a read-only property.

class Test(object):
    def getProperty(self):
        return 0;

    prop = property(fget = getProperty)
    
t = Test()

print t.prop

t.prop = 100 # this will fail




More information about the Python-list mailing list