Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查的新方法是什么;“可赎回”;Python3.x中的方法?_Python_Python 3.x_Introspection - Fatal编程技术网

检查的新方法是什么;“可赎回”;Python3.x中的方法?

检查的新方法是什么;“可赎回”;Python3.x中的方法?,python,python-3.x,introspection,Python,Python 3.x,Introspection,我在研究Python中的内省,在学习基本示例时,我发现,callable内置函数在Python 3.1中不再可用 如何检查方法现在是否可调用 多谢各位 if hasattr(f, "__call__"): Py2.x中的callable()内置函数在python3.2中复活。并不是所有可以调用的都是collections.callable的实例。@Jasperbyant Greene你有例子吗?我能找到的唯一一件事是Python 2老式类(类对象本身,即不是其实例),它在Python 3中根本

我在研究Python中的内省,在学习基本示例时,我发现,
callable
内置函数在Python 3.1中不再可用

如何检查方法现在是否可调用

多谢各位

if hasattr(f, "__call__"):

Py2.x中的callable()内置函数在python3.2中复活。

并不是所有可以调用的都是collections.callable的实例。@Jasperbyant Greene你有例子吗?我能找到的唯一一件事是Python 2老式类(类对象本身,即不是其实例),它在Python 3中根本不存在。您能提供一个用法吗?我可以:
如果可调用(f):print('f is callable')
;)
isinstance(f, collections.Callable)