Re: Overriding methods per-object

2009-04-19 Thread Pavel Panchekha
On Apr 18, 9:43 pm, Aaron Brady wrote: > On Apr 17, 9:41 pm, Steven D'Aprano > cybersource.com.au> wrote: > > On Fri, 17 Apr 2009 18:22:49 -0700, Pavel Panchekha wrote: > > > I've got an object which has a method, __nonzero__ The problem is, that > > > method is attached to that object not that c

Re: Overriding methods per-object

2009-04-18 Thread Aaron Brady
On Apr 17, 9:41 pm, Steven D'Aprano wrote: > On Fri, 17 Apr 2009 18:22:49 -0700, Pavel Panchekha wrote: > > I've got an object which has a method, __nonzero__ The problem is, that > > method is attached to that object not that class > > >> a = GeneralTypeOfObject() > >> a.__nonzero__ = lambda: Fal

Re: Overriding methods per-object

2009-04-18 Thread Gabriel Genellina
En Sat, 18 Apr 2009 19:39:24 -0300, Pavel Panchekha escribió: On Apr 18, 4:01 pm, Piet van Oostrum wrote: But you can give each object its own class and then put the special methods in that class: >>> def create_special_object(bases, *args): ...   if not isinstance(bases, tuple): ...    

Re: Overriding methods per-object

2009-04-18 Thread Pavel Panchekha
On Apr 18, 4:01 pm, Piet van Oostrum wrote: > But you can give each object its own class and then put the special > methods in that class: > > >>> def create_special_object(bases, *args): > > ...   if not isinstance(bases, tuple): > ...      bases = bases, > ...   cls = type("SpecialClass", bases,

Re: Overriding methods per-object

2009-04-18 Thread Piet van Oostrum
> Pavel Panchekha (PP) wrote: >>> The docs don't say you can do that: >PP> Thanks, hadn't noticed that. >>> Should you be able to? >PP> I'd say so. In my case, I need a class that can encapsulate any >PP> object, add a few methods to it, and spit something back that works >PP> just like the

Re: Overriding methods per-object

2009-04-17 Thread George Sakkis
On Apr 17, 9:22 pm, Pavel Panchekha wrote: > I've got an object which has a method, __nonzero__ > The problem is, that method is attached to that object not that class > > > a = GeneralTypeOfObject() > > a.__nonzero__ = lambda: False > > a.__nonzero__() > > False > > But: > > > bool(a) > > True >

Re: Overriding methods per-object

2009-04-17 Thread Steven D'Aprano
On Fri, 17 Apr 2009 18:22:49 -0700, Pavel Panchekha wrote: > I've got an object which has a method, __nonzero__ The problem is, that > method is attached to that object not that class > >> a = GeneralTypeOfObject() >> a.__nonzero__ = lambda: False >> a.__nonzero__() > False > > But: > >> bool(a

Re: Overriding methods per-object

2009-04-17 Thread Aaron Brady
On Apr 17, 9:28 pm, Pavel Panchekha wrote: > > The docs don't say you can do that: > > Thanks, hadn't noticed that. > > > Should you be able to? > > I'd say so. In my case, I need a class that can encapsulate any > object, add a few methods to it, and spit something back that works > just like the

Re: Overriding methods per-object

2009-04-17 Thread Pavel Panchekha
> The docs don't say you can do that: Thanks, hadn't noticed that. > Should you be able to? I'd say so. In my case, I need a class that can encapsulate any object, add a few methods to it, and spit something back that works just like the object, but also has those extra methods. I can't just add

Re: Overriding methods per-object

2009-04-17 Thread Aaron Brady
On Apr 17, 8:22 pm, Pavel Panchekha wrote: > I've got an object which has a method, __nonzero__ > The problem is, that method is attached to that object not that class > > > a = GeneralTypeOfObject() > > a.__nonzero__ = lambda: False > > a.__nonzero__() > > False > > But: > > > bool(a) > > True >

Re: Overriding methods per-object

2009-04-17 Thread Chris Rebert
On Fri, Apr 17, 2009 at 6:22 PM, Pavel Panchekha wrote: > I've got an object which has a method, __nonzero__ > The problem is, that method is attached to that object not that class > >> a = GeneralTypeOfObject() >> a.__nonzero__ = lambda: False >> a.__nonzero__() > False > > But: > >> bool(a) > Tr

Overriding methods per-object

2009-04-17 Thread Pavel Panchekha
I've got an object which has a method, __nonzero__ The problem is, that method is attached to that object not that class > a = GeneralTypeOfObject() > a.__nonzero__ = lambda: False > a.__nonzero__() False But: > bool(a) True What to do? -- http://mail.python.org/mailman/listinfo/python-list