Tweepy list_members python

断了今生、忘了曾经 提交于 2019-12-09 07:58:50

问题


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.

Here is the code:

the_list = api.list_members('username', 'listname')
for user in the_list:
    print user

Here is what I get:

tweepy.models.User object at 0x90b78ec (0, 0)

That doesn't look like list_members to me. I want to create a normal python list of just the usernames.

Thanks for any help.


回答1:


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]

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

Incidentally, you should choose a more informative name than the_list. Perhaps user_names or list_members or something.



来源:https://stackoverflow.com/questions/5469768/tweepy-list-members-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!