type(foo) == function ?

Chris Mellon arkanes at gmail.com
Wed Nov 29 21:26:15 CET 2006


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.

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



More information about the Python-list mailing list