作者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
1F:→ hilorrk:type()? 05/27 22:28
2F:→ aquarianboy:type(author) ? 05/27 22:28
3F:→ hilorrk:不过一般来说型别错误会丢exception吧... 05/27 22:31
4F:→ AndCycle:exception也要等用到了才会踢出来呀, 有时候有点麻烦 05/27 23:46
※ 编辑: phkmalloc 来自: 220.135.222.237 (05/28 06:59)
5F:→ webbsboard: isinstance or __class__ 05/29 20:44