Re: overriding a property

2010-10-20 Thread Hrvoje Niksic
Lucasm writes: > Thanks for the answers. I would like to override the property though > without making special modifications in the main class beforehand. Is > this possible? That will not be easy. When you access obj.return_five, python looks up 'return_five' in type(obj) to see what the retur

Re: overriding a property

2010-10-20 Thread John Posner
On 10/20/2010 9:59 AM, Lucasm wrote: Thanks for the answers. I would like to override the property though without making special modifications in the main class beforehand. Is this possible? Take a look at http://docs.python.org/reference/datamodel.html#descriptors The last paragraph of Sec

Re: overriding a property

2010-10-20 Thread Lucasm
On 20 Okt, 16:09, Peter Otten <__pete...@web.de> wrote: > Lucasm wrote: > > On 19 Okt, 18:28, Steven D'Aprano > cybersource.com.au> wrote: > >> On Tue, 19 Oct 2010 06:39:56 -0700, Lucasm wrote: > >> > Hi, > > >> > A question. Is it possible to dynamically override a property? > > >> > class A(obje

Re: overriding a property

2010-10-20 Thread Peter Otten
Lucasm wrote: > On 19 Okt, 18:28, Steven D'Aprano cybersource.com.au> wrote: >> On Tue, 19 Oct 2010 06:39:56 -0700, Lucasm wrote: >> > Hi, >> >> > A question. Is it possible to dynamically override a property? >> >> > class A(object): >> > @property >> > def return_five(self): >> > return 5 >> >>

Re: overriding a property

2010-10-20 Thread Lucasm
On 19 Okt, 18:28, Steven D'Aprano wrote: > On Tue, 19 Oct 2010 06:39:56 -0700, Lucasm wrote: > > Hi, > > > A question. Is it possible to dynamically override a property? > > > class A(object): > >     @property > >     def return_five(self): > >         return 5 > > > I would like to override the

Re: overriding a property

2010-10-20 Thread Lucasm
On 19 Okt, 16:07, Benjamin Peterson wrote: > Lucasm gmail.com> writes: > > > I would like to override the property for an instance of A to say the > > string 'bla'. > > A.return_five = "blah" I guess you did not test that. :) -- http://mail.python.org/mailman/listinfo/python-list

Re: overriding a property

2010-10-19 Thread Steven D'Aprano
On Tue, 19 Oct 2010 06:39:56 -0700, Lucasm wrote: > Hi, > > A question. Is it possible to dynamically override a property? > > class A(object): > @property > def return_five(self): > return 5 > > I would like to override the property for an instance of A to say the > string 'bla

Re: overriding a property

2010-10-19 Thread John Posner
On 10/19/2010 9:39 AM, Lucasm wrote: Hi, A question. Is it possible to dynamically override a property? class A(object): @property def return_five(self): return 5 I would like to override the property for an instance of A to say the string 'bla'. Is this the sort of thing

Re: overriding a property

2010-10-19 Thread Benjamin Peterson
Lucasm gmail.com> writes: > I would like to override the property for an instance of A to say the > string 'bla'. A.return_five = "blah" -- http://mail.python.org/mailman/listinfo/python-list

overriding a property

2010-10-19 Thread Lucasm
Hi, A question. Is it possible to dynamically override a property? class A(object): @property def return_five(self): return 5 I would like to override the property for an instance of A to say the string 'bla'. -- http://mail.python.org/mailman/listinfo/python-list