Re: How to mix-in __getattr__ after the fact?

2011-11-07 Thread Steven D'Aprano
On Tue, 08 Nov 2011 15:17:14 +1100, Lie Ryan wrote: > On 10/31/2011 11:01 PM, dhyams wrote: >> >> Thanks for all of the responses; everyone was exactly correct, and >> obeying the binding rules for special methods did work in the example >> above. Unfortunately, I only have read-only access to th

Re: How to mix-in __getattr__ after the fact?

2011-11-07 Thread Lie Ryan
On 10/31/2011 11:01 PM, dhyams wrote: Thanks for all of the responses; everyone was exactly correct, and obeying the binding rules for special methods did work in the example above. Unfortunately, I only have read-only access to the class itself (it was a VTK class wrapped with SWIG), so I had

Re: How to mix-in __getattr__ after the fact?

2011-11-01 Thread DevPlayer
On Oct 31, 8:01 am, dhyams wrote: > Thanks for all of the responses; everyone was exactly correct, and > obeying the binding rules for special methods did work in the example > above.  Unfortunately, I only have read-only access to the class > itself (it was a VTK class wrapped with SWIG), so I ha

Re: How to mix-in __getattr__ after the fact?

2011-10-31 Thread dhyams
Thanks for all of the responses; everyone was exactly correct, and obeying the binding rules for special methods did work in the example above. Unfortunately, I only have read-only access to the class itself (it was a VTK class wrapped with SWIG), so I had to find another way to accomplish what I

Re: How to mix-in __getattr__ after the fact?

2011-10-28 Thread Lie Ryan
On 10/29/2011 05:20 AM, Ethan Furman wrote: Python only looks up __xxx__ methods in new-style classes on the class itself, not on the instances. So this works: 8< class Cow(object): pass def attrgetter(self, a): print "CAUGHT: At

Re: How to mix-in __getattr__ after the fact?

2011-10-28 Thread Ethan Furman
dhyams wrote: Python 2.7.2 I'm having trouble in a situation where I need to mix-in the functionality of __getattr__ after the object has already been created. Here is a small sample script of the situation: =snip import types class Cow(object): pass # this __getattr__ works

Re: How to mix-in __getattr__ after the fact?

2011-10-28 Thread Jerry Hill
On Fri, Oct 28, 2011 at 1:34 PM, dhyams wrote: > If I call __getattr__ directly, as in bessie.__getattr__('foo'), it > works as it should obviously; so the method is bound and ready to be > called.  But Python does not seem to want to call __getattr__ > appropriately if I mix it in after the objec

How to mix-in __getattr__ after the fact?

2011-10-28 Thread dhyams
Python 2.7.2 I'm having trouble in a situation where I need to mix-in the functionality of __getattr__ after the object has already been created. Here is a small sample script of the situation: =snip import types class Cow(object): pass # this __getattr__ works as advertised.