Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the new way of checking "callable" methods in python 3.x?

I was studying introspection in Python, and as I was getting through basic examples, I found out that the callable built-in function is no longer available in Python 3.1.

How can I check if a method is callable now?

Thank you

like image 684
Olivier Girardot Avatar asked Mar 12 '10 18:03

Olivier Girardot


3 Answers

The callable() builtin function from Py2.x was resurrected in python3.2.

like image 158
Luis Gomes Avatar answered Sep 28 '22 06:09

Luis Gomes


if hasattr(f, "__call__"):

What's New In Python 3.0

like image 23
cobbal Avatar answered Sep 28 '22 04:09

cobbal


isinstance(f, collections.Callable)
like image 42
SilentGhost Avatar answered Sep 28 '22 04:09

SilentGhost