other ways to check for <type 'function'>?

ArdPy ardsrk at gmail.com
Thu Nov 2 13:46:00 CET 2006


elderic wrote:
> Hi there,
>
> are there other ways than the ones below to check for <type 'function'>
> in a python script?
> (partly inspired by wrapping Tkinter :P)
>
> def f():
>    print "This is f(). Godspeed!"
>
> 1.: --> sort of clumsy and discouraged by the docs as far as I read
> import types
> type(f) is types.FunctionType
>
> 2.: --> I don't like this one at all
> def null(): pass
> type(f) is type(null)
>
> Basically I'm searching for something like:
> "type(f) is func" like in: "type(x) is int"
>
> Any ideas? =)

you could use assert. Like the one below

assert inspect.isfunction(function_name)




More information about the Python-list mailing list