Why 'open' is not a function according to inspect module?

Ian Kelly ian.g.kelly at gmail.com
Tue Jun 22 11:55:25 EDT 2010


On Tue, Jun 22, 2010 at 9:42 AM, Peng Yu <pengyu.ut at gmail.com> wrote:
> Hi,
>
> 'open' is not a function according to inspect module. But according to
> help(open), it is a function. Is there something wrong with inspect
> module?
>
> $ cat main.py
> #!/usr/bin/env python
>
> import inspect
>
> def hello():
>  print "Hello World!"
>  return
>
> print inspect.isfunction(str)
> print inspect.isfunction(open)
> print inspect.isfunction(hello)

inspect.isfunction returns True if the object is a *user-defined*
function.  For built-in functions, use inspect.isbuiltin.  You might
also be interested in the callable() function, which returns True if
the object is any object that can be called.

Cheers,
Ian



More information about the Python-list mailing list