On 12/18/2010 2:06 AM, Peter Otten wrote:
I don't think /how/ you are trying it is stupid though I'm not so sure about /what/ .
Thank you all for very helpful suggestions. It took me a while to chew on this before I could respond. I learned a lot about descriptors and their interactions with properties that I hadn't fully understood before.
Peter and Alan's advice to create a check method that is overridden in subclasses makes sense in order to avoid the naming conflicts. And I also like Hugo's idea of applying separate descriptor classes to handle the constraints introduced. That seems to be a flexible way of doing things.
As far as the /what/, my example given was obviously contrived. I'm really trying to create classes for 2D envelopes that describe the bounding extent of spatial data. I have both Envelope and RasterEnvelope classes - the former being just a bounding box around any spatial data, the latter additionally specifying a raster cell size and being able to discern rows, columns, etc.
I had been using the setter to do bounds checking on the Envelope class (e.g. make sure x_min isn't bigger than x_max, etc. and rolling back changes if so). For the RasterEnvelope class, I first wanted to call the Envelope bounds checking and then to adjust rows/columns if a bigger extent was requested. But you've successfully scared me away from using properties (in a hierarchical way at least) and I've been able to get what I need by just defining __setattr__ in both classes. Whether I did that correctly is a story for another thread ...
matt _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor