Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top