Tuesday, October 18, 2011

The Python Property Builtin:

'via Blog this'

I thought attribute accessors are a good idea until I saw Python's approach to it: properties! Basically, you still write accessors, say, get_x and set_x, but then by including
x = property(self.get_x, self.set_x) the class user can use A.x as if it were an attribute. The advantage over an attribute is that set_x and get_x can contain code.

No comments: