importing a method

Martin Miller ggrp1.20.martineau at dfgh.net
Mon Nov 28 11:16:12 EST 2005


First of all,why do you think the new module is deprecated?  (I can't
find anything in the docs to indicate this.)

As for using MethodType in the types module:  There's nothing in the
module documentation that suggests that you can call MethodType as a
function as you suggest, only that it is the name of the type of
methods of user-defined class instances..  So, while calling it might
work, it sounds like you are using an undocumented feature...

Lastly, in an earlier post after Ben Finney suggested using the
new.instancemethod function, you replied:
> If you read my original post, I had no intention of atributing the
> user's method to the class, but to the instance.

I'd like to point out that the instancemethod() function returns a
method object, bound to its *instance* argument if it isn't None --
which sounds like exactly what you want/need.

-Martin


Flavio wrote:
> Addendum to my last reply:
>
> although the New Method is deprecated,
>
> new.instancemethod (from Antoon's message) can be replaced by
>
> from types import MethodType
> 
> f.show = MethodType(show,f)
> 
> and every thing still works.




More information about the Python-list mailing list