开发者

Tweepy list_members python

开发者 https://www.devze.com 2023-02-20 16:31 出处:网络
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 whack开发者_Go百科ed out.

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 whack开发者_Go百科ed 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消