On 8/20/2010 8:35 PM, bob gailer wrote:
After yet more thought it gets even more better: I even added a unit test.
class PointND(list): def __init__(self, *a_list): super(PointND, self).__init__(a_list)
def getSet(ix): def chklen(self): if len(self) < ix + 1: raise AttributeError def get(self): chklen(self) return self[ix] def set(self, value): chklen(self) self[ix] = value return property(get, set) def set(self, ix): return s x = getSet(0) y = getSet(1) z = getSet(2) p = PointND(1,2,3) assert (p.x, p.y, p.z) == (1, 2, 3) p.x = 6; p.y = 9; p.z = 5 assert (p.x, p.y, p.z) == (6, 9, 5) try: p = PointND(1,2) p.z = 3 except AttributeError: print 'Passed all tests' except: print 'some other exception' -- Bob Gailer 919-636-4239 Chapel Hill NC _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor