如何在Python中遍历对象的属性?
我有一堂课:
class Twitt:
def __init__(self):
self.usernames = []
self.names = []
self.tweet = []
self.imageurl = []
def twitter_lookup(self, coordinents, radius):
cheese = []
twitter = Twitter(auth=auth)
coordinents = coordinents + “,” + radius
print coordinents
query = twitter.search.tweets(q=””, geocode=coordinents, rpp=10)
for result in query[“statuses”]:
self.usernames.append(result[“user”][“screen_name”])
self.names.append(result[‘user’][“name”])
self.tweet.append(h.unescape(result[“text”]))
self.imageurl.append(result[‘user’][“profile_image_url_https”])
现在,我可以通过执行以下操作获取我的信息:
k = Twitt()
k.twitter_lookup(“51.5033630,-0.1276250”, “1mi”)
print k.names
我想要做的是像这样循环遍历for循环中的属性:
for item in k:
print item.names