The keyword __object__xattributes__
is used to define attributes
which do not appear in the constructor. Note that the default mode
for attributes in __object__xattributes__
is readonly ('r'
).
If you want this attribute to be readwrite ('rw'
), you must specify it like that:
# -- # Copyright (C) CEA, EDF # Author : Erwan ADAM (CEA) # -- import unittest from xdata import * class A(XObject): __object__xattributes__ = [ XAttribute("x", xtype=XInt(min=0), mode='rw'), ] pass class ATestCase(unittest.TestCase): def test(self): a = A() a.x = 1 self.failUnlessEqual(a.x, 1) a.setX(2) self.failUnlessEqual(a.getX(), 2) return pass if __name__ == '__main__': unittest.main() pass
Of course, on the same way than attributes defined in __init__xattributes__
,
you can define your own accessors for the __object__xattributes__
attributes:
# -- # Copyright (C) CEA, EDF # Author : Erwan ADAM (CEA) # -- import unittest from xdata import * class A(XObject): __object__xattributes__ = [ XAttribute("x", xtype=XInt(min=0), mode='rw'), ] def setX(self, value): self.test = 1 return pass class ATestCase(unittest.TestCase): def test(self): a = A() a.x = 1 self.failUnlessEqual(a.test, 1) return pass if __name__ == '__main__': unittest.main() pass