[Tutor] How can I have type "function" in my script?

Emile van Sebille emile at fenx.com
Wed May 9 00:28:49 CEST 2012


On 5/8/2012 3:14 PM Alan Gauld said...
> On 08/05/12 19:42, Emile van Sebille wrote:
>
>> >>> from types import *
>> >>> def test():pass
>> ...
>> >>> function=FunctionType
>> >>> print isinstance(test,function)
>
> Wow, thanks for that. I knew about all the different function types in
> there but hadn't realised that FunctionType was the grandaddy of them
> all... although I should probably have guessed there would be a parent
> class.



Yes -- but not quite the grandaddy... :)


 >>> class Test:
...     def testm(self):pass
...
 >>> T=Test.testm
 >>> print isinstance(T,function)
False
 >>> print isinstance(T,MethodType)
True
 >>>

your point elsewhere re callable is likely more relevant to the OP but 
who knows...

Emile




More information about the Tutor mailing list