Olivier Girardot
Olivier Girardot

Reputation: 4648

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

Upvotes: 13

Views: 4252

Answers (3)

Luis Gomes
Luis Gomes

Reputation: 231

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

Upvotes: 23

SilentGhost
SilentGhost

Reputation: 319821

isinstance(f, collections.Callable)

Upvotes: 4

cobbal
cobbal

Reputation: 70763

if hasattr(f, "__call__"):

What's New In Python 3.0

Upvotes: 8

Related Questions