Re: Best way to set/get an object property

2008-08-26 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : (snip) But it's quite rare to see double-underscore "really private" attributes in Python code. It is considered to go against the spirit of the language. Not necessarily "against the spirit" - it's mostly than __name_mangling is only really useful when you want to pr

Re: Best way to set/get an object property

2008-08-25 Thread Hussein B
On Aug 25, 4:31 am, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sun, 24 Aug 2008 23:56:27 -0700, Hussein B wrote: > > On Aug 24, 7:12 pm, Steven D'Aprano <[EMAIL PROTECTED] > > cybersource.com.au> wrote: > >> >> I noted that Python encourage the usage of: -- obj.prop = data > >> >> x = obj.prop

Re: Best way to set/get an object property

2008-08-25 Thread Ken Seehart
This is probably what you want: http://www.python.org/download/releases/2.2/descrintro/#property Available in Python 2.2 or later. Enjoy, Ken Seehart Hussein B wrote: Hey, I noted that Python encourage the usage of: -- obj.prop = data x = obj.prop -- to set/get an object's property value. Wha

Re: Best way to set/get an object property

2008-08-25 Thread Steven D'Aprano
On Sun, 24 Aug 2008 23:56:27 -0700, Hussein B wrote: > On Aug 24, 7:12 pm, Steven D'Aprano <[EMAIL PROTECTED] > cybersource.com.au> 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 t

Re: Best way to set/get an object property

2008-08-25 Thread alex23
On Aug 25, 4:56 pm, Hussein B <[EMAIL PROTECTED]> wrote: > AFAIUY (understand you), what it is called a property in Java, it is > called an attribute in Python? > Why Python encourages direct access to object's attributes? The simplest answer is "Because Python is not Java" :) Speaking of which,

Re: Best way to set/get an object property

2008-08-25 Thread Hussein B
On Aug 24, 7:12 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Sun, 24 Aug 2008 12:28:53 +0200, Peter Otten 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 v

Re: Best way to set/get an object property

2008-08-24 Thread Steven D'Aprano
On Sun, 24 Aug 2008 12:28:53 +0200, Peter Otten 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 pref

Re: Best way to set/get an object property

2008-08-24 Thread castironpi
On Aug 24, 5:07 am, Hussein B <[EMAIL PROTECTED]> wrote: > Hey, > 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

Re: Best way to set/get an object property

2008-08-24 Thread Hussein B
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

Re: Best way to set/get an object property

2008-08-24 Thread Peter Otten
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')? >

Best way to set/get an object property

2008-08-24 Thread Hussein B
Hey, 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 __s