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

Alan Gauld alan.gauld at btinternet.com
Wed May 9 00:14:05 CEST 2012

On 08/05/12 19:42, Emile van Sebille wrote:

>  >>> from types import *
>  >>> dir()
> ['BooleanType', 'BufferType', 'BuiltinFunctionType',
> 'BuiltinMethodType', 'ClassType', 'CodeType', 'ComplexType',
> 'DictProxyType', 'DictType', 'DictionaryType', 'EllipsisType',
> 'FileType', 'FloatType', 'FrameType', 'FunctionType', 'GeneratorType',
> 'GetSetDescriptorType', 'InstanceType', 'IntType', 'LambdaType',
> 'ListType', 'LongType', 'MemberDescriptorType', 'MethodType',
> 'ModuleType', 'NoneType', 'NotImplementedType', 'ObjectType',
> 'SliceType', 'StringType', 'StringTypes', 'TracebackType', 'TupleType',
> 'TypeType', 'UnboundMethodType', 'UnicodeType', 'XRangeType',
> '__builtins__', '__doc__', '__name__', '__package__']
>  >>> 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 

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list