作者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)
→ sbrhsieh:抱歉,我 OP 了 07/09 20:30
推 timTan:長知識! 07/09 23:07
推 os653:講的很清楚呀 07/10 03:41