type(foo) == function ?

Mathias Panzenboeck e0427417 at student.tuwien.ac.at
Fri Dec 1 18:13:33 EST 2006


Chris Mellon wrote:
> On 11/29/06, Tom Plunket <tomas at fancy.org> wrote:
>> I'd like to figure out if a given parameter is a function or not.
>>
>> E.g.
>>
>> >>> type(1)
>> <type 'int'>
>> >>> type(1) == int
>> True
>>
>> implies:
>>
>> >>> def foo():
>> ...   pass
>> ...
>> >>> type(foo)
>> <type 'function'>
>> >>> type(foo) == function
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>> NameError: name 'function' is not defined
>>
>> Is there a way I can know if 'foo' is a function?
>>
> 
>>>> def foo():
> ...     pass
> ...
>>>> from inspect import isfunction
>>>> isfunction(foo)
> True
>>>>
> 
> 
> But you probably want the callable() builtin instead.
> 

This builtin will be removed in python 3.0!

>> thanks,
>> -tom!
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
>>



More information about the Python-list mailing list