From: Thomas K. <th...@kl...> - 2013-03-15 18:02:18
|
On 15 March 2013 17:18, Nathaniel Smith <nj...@po...> wrote: > On 15 Mar 2013 16:50, "Todd" <tod...@gm...> wrote: > > Within the axes constructor, the constructor would run through each of > these modules and store them as attributes with the same name as the > function and the function itself being the contents. At least if me > understanding is correct, this would make them behave as methods (since > they are already set up to take an axes instance as their first argument). > > This won't work as described - the function -> unbound method -> bound > method magic only happens for attributes that aren't found in the object > dict, when lookup falls back on the type dict. You'll want to inject the > functions into the Axes type object, either via a metaclass constructor or > just by hand after the type is created. > You can manually create bound methods using types.MethodType, if necessary. However, I think adding them to the class is preferable. Thomas |