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

Emile van Sebille emile at fenx.com
Tue May 8 20:42:32 CEST 2012

On 5/8/2012 11:31 AM xancorreu said...
> isinstance(2, function)
> like I do
> isinstance(2, int)
> Do you understand my reasoning?

Nope, but here ya go:

Python 2.6.4rc2 (r264rc2:75497, Oct 20 2009, 02:55:11)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> 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)

More information about the Tutor mailing list