On Aug 24, 5:28 am, Peter Otten <[EMAIL PROTECTED]> wrote: > Hussein B wrote: > > I noted that Python encourage the usage of: > > -- > > obj.prop = data > > x = obj.prop > > -- > > to set/get an object's property value. > > What if I want to run some logic upon setting/getting a property? > > What is Python preferred method to do so (using the new feature > > 'property')? > > I don't think __getattr__ and __setattr__ are practical (I have to > > code the property name into them). > > Hussein, I don't think you'll learn much from asking these abstract > questions. At some point you have to get your hands dirty and write actual > code to get a feel for the language. > > For example, it will then become obvious for you that property works best > for individual attributes while __getattr__ and friends are more convenient > if you want to treat multiple attributes the same way, attributes whose > names may not even be known until runtime (think delegation). > > Peter
Thanks Peter, You are right, I have to try to touch the Python but the problem is I don't have much time to do so. I have a Java developer for more than 4 years and I find it is not so easy to digest Python concepts, this is why I'm asking a lot of obvious and clear easy to you (long time Pythonists). Thank you for your time. -- http://mail.python.org/mailman/listinfo/python-list