作者sbrhsieh (十年~)
看板Python
标题Re: [问题] 请教一个很蠢的问题@@
时间Tue Jul 9 20:25:35 2013
有个 module 叫 types,内建的 type/class 都放在这个 module 里,包括
old-style class 的共通型别(types.ClassType),old-style object 的共通
型别 types.InstanceType。
当你想要某种 builtin 型别的 type object reference,你没有办法直接写出
type literal(比如你例中的 function type),记得来这个 module 找。
def statement 执行後产生的 function object 是 types.FunctionType 的
instance。
def foo(): pass
isinstance(foo, types.FunctionType) // True
type(foo) is types.FunctionType // True
foo.__class__ is types.FunctionType // True
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 1.173.253.133
※ 编辑: sbrhsieh 来自: 1.173.253.133 (07/09 20:27)
1F:→ sbrhsieh:抱歉,我 OP 了 07/09 20:30
2F:推 timTan:长知识! 07/09 23:07
3F:推 os653:讲的很清楚呀 07/10 03:41