The resource has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this resource. This resource will be reviewed shortly. If you think this resource contain inappropriate content, please report to webmaster. |
Creating propeties in ironpython is some what different from c#. we can use property function to achieve this . below code demonstrates this CODE] class testclass1(object): def __init__(self): self.__x = None self.__y = "y"
def getx(self): return self._x
def setx(self, value): self._x = value def delx(self): del self._x
x = property(getx, setx, delx, "I'm the 'x' property.") def gety(self): return self.__y #read only property y = property(gety,None,None, "I'm the 'y' property.")
obj = testclass1() obj.x = "x"; print obj.x print obj.y
class Parrot(object): def __init__(self): self._voltage = 100000
#Another way of defining ready only property using decorators @property def voltage(self): """Get the current voltage.""" return self._voltage
objparrot = Parrot()
#this gives error as it is read only property #objparrot.voltage = "20000" print objparrot.voltage
|
No responses found. Be the first to respond and make money from revenue sharing program.
|