作者phkmalloc ( )
看板Python
標題[問題] 如何知道 class member 的type
時間Thu May 27 22:19:16 2010
初學python
一直不知道怎樣知道class member 的type
ex:
http://tinyurl.com/34n8p2n
class YouTubeVideoEntry(gdata.GDataEntry)
__init__(self, author=None, category=None, content=None, atom_id=None,
link=None, published=None, title=None, updated=None, rating=None,
noembed=None, statistics=None, racy=None, media=None, geo=None,
recorded=None, comments=None, extension_elements=None,
extension_attributes=None)
怎麼會知道裡面的author, category, content 是什麼type
也許是list, tuple, class instance ..... ?
這樣如何繼續操作member ?
thanks
假設說member 是type class A;
但是我根本不知道他是class A 的instance
那我在寫程式時候怎麼去使用class A的member, function ?
用type() ? 這也要等到runtime 才會知道~~~
那寫程式時 程式員不是非常困擾嗎?
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.87.71.10
→ hilorrk:type()? 05/27 22:28
→ aquarianboy:type(author) ? 05/27 22:28
→ hilorrk:不過一般來說型別錯誤會丟exception吧... 05/27 22:31
→ AndCycle:exception也要等用到了才會踢出來呀, 有時候有點麻煩 05/27 23:46
※ 編輯: phkmalloc 來自: 220.135.222.237 (05/28 06:59)
→ webbsboard: isinstance or __class__ 05/29 20:44