【发布时间】:2012-08-24 12:04:32
【问题描述】:
我在 python 2.7 中工作。我一直在试验tweepy 包。有一个对象叫做 tweepy.models.status 对象,它的功能在这里定义:https://github.com/tweepy/tweepy/blob/master/tweepy/models.py。
我有一个看起来像这样的函数:
def on_status(self, status):
try:
print status
return True
except Exception, e:
print >> sys.stderr, 'Encountered Exception:', e
pass
我所指的对象是从on_status 函数返回的对象,称为status。当print status 行执行时,我会将其打印在屏幕上;
tweepy.models.Status 对象位于 0x85d32ec>
我的问题实际上很笼统。我想知道如何直观地打印出这个status 对象的内容?我想知道这个对象里面有什么信息。
我尝试了for i, v in status : 方法,但它说这个对象是不可迭代的。此外,并非所有对象属性都在函数定义中进行了描述。
非常感谢!
【问题讨论】:
-
+1 并已收藏。我通常只使用
dir,但现在 mgilson 的回答给了我一些更具体的重复使用的东西。想要补充: Dive Into Python (for v2, first one) 有一章关于introspection with anapihelper->infofunction。还提供了有关成员等的一些有用信息,以及文档字符串中的文档。
标签: python object introspection tweepy