Tweepy list_members python [英] Tweepy list_members python
问题描述
我在 twitter 上创建了一个列表并添加了一个用户.然后我终于想出了如何编写没有错误的代码.我是新手.然后瞧瞧,当我得到数据时,它被打掉了.我不知道该怎么办.
I created a list on twitter and added a user to it. Then I finally figured out how to write the code without an error. I am a newbie. Then Lo and behold when i get data it is whacked out. I have no idea what to do with it.
我想要的只是获取列表中每个人的用户名.
All I want is to get the usernames of everyone in the the list.
代码如下:
the_list = api.list_members('username', 'listname')
for user in the_list:
print user
这是我得到的:
tweepy.models.User 对象在 0x90b78ec(0, 0)
tweepy.models.User object at 0x90b78ec (0, 0)
对我来说这看起来不像 list_members.我想创建一个仅包含用户名的普通 python 列表.
That doesn't look like list_members to me. I want to create a normal python list of just the usernames.
感谢您的帮助.
推荐答案
列表中的每个元素都是一个 User
对象,其中包含有关用户的更多信息,而不仅仅是他们的姓名.如果你只想要名字,做
Each element of the list is a User
object, which holds more information about the user than just their name. If you want just the names, do
the_list = [u.screen_name for u in the_list]
在调用 api.list_members
之后.或者您可以将两者结合起来:
after calling api.list_members
. Or you can combine the two:
the_list = [u.screen_name for u in api_list_members('username','listname')
或者您可以仅在显示名称时提取名称:
or you can extract the names only when you're displaying them:
the_list = api.list_members('username','listname')
for user in the_list:
print user.screen_name
顺便说一下,您应该选择一个比 the_list
信息更丰富的名称.可能是 user_names
或 list_members
之类的.
Incidentally, you should choose a more informative name than the_list
. Perhaps user_names
or list_members
or something.
这篇关于Tweepy list_members python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!