其他检查< type'function'>?的方法 [英] other ways to check for <type 'function'>?

查看:54
本文介绍了其他检查< type'function'>?的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


还有其他方法可以检查< type''function''>

in python脚本?

(部分灵感来自包装Tkinter:P)


def f():

print" this is f ()。 Godspeed!


1: - 据我所知,文件很笨拙而气馁

导入类型

type(f)是types.FunctionType


2: - 我根本不喜欢这个

def null():通过

类型(f)是类型(null)


基本上我正在寻找类似的东西:

" type(f)is func喜欢在:类型(x)是int


任何想法? =)

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? =)

推荐答案

elderic写道:
elderic wrote:

还有其他方法比下面的那些在python脚本中检查< type''function''>


are there other ways than the ones below to check for <type ''function''>
in a python script?



可赎回(f)


< / F>

callable(f)

</F>


Thx =)


Fredrik Lundh schrieb:
Thx =)

Fredrik Lundh schrieb:

elderic写道:
elderic wrote:

还有其他方法可以在python脚本中检查< type''function''>


are there other ways than the ones below to check for <type ''function''>
in a python script?



可赎回(f)


< / F>


callable(f)

</F>


elderic启发我们:
elderic enlightened us with:

还有其他方法可以检查以下方式来检查for< type

''function''在python脚本中?
are there other ways than the ones below to check for <type
''function''in a python script?



首先,你为什么要这样做?如果你想将对象

作为函数调用,就这样做。处理

它被提出时引发的异常。


Sybren

-

Sybren St ?? vel

St ?? vel IT - http: //www.stuvel.eu/


这篇关于其他检查&lt; type'function'&gt;?的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆