Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import types
>>> help(types.FunctionType)
Help on class function in module __builtin__:
class function(object)
| function(code, globals[, name[, argdefs[, closure]]])
|
| Create a function object from a code object and a dictionary.
| The optional name string overrides the name from the code object.
| The optional argdefs tuple specifies the default argument values.
| The optional closure tuple supplies the bindings for free variables.
你应该摆脱Python中“类型”的概念。大多数时候你不想检查某个东西的“类型”。显式检查类型容易损坏,例如:
您要做的是检查对象是否支持您试图对其执行的任何操作。在
如果要查看给定对象是否为函数,请执行以下操作:
^{pr2}$或者尝试调用它,然后捕捉异常!在
“什么Python内置函数返回
<type 'function'>
?”在功能。在
有没有办法避免创建这个lambda函数,以便获得函数的一般类型在
是的,类型.函数类型. 或者只输入(anyfunction)
如果你在问如何去除lambda(但是重读后我发现你可能不是),你可以定义一个函数而不是lambda。在
所以不是:
你知道吗
^{pr2}$您应该能够使用
types.FunctionType
来执行您想要的操作:但是通常,
def
被认为是function
类型的默认构造函数。在相关问题 更多 >
编程相关推荐