Home > Enterprise >  how to jump a list member in python?
how to jump a list member in python?

Time:03-27

so I'm trying to send i message to a group of people . I want to know how can I jump to 'test2' (next list member ) if 'test1' (current list member ) got an error .

profile_id = ['test1','test2']
for ids in profile_id:
    api.send_direct_message(profile_id,text)

CodePudding user response:

for iterates trough iprofile_id. So, the variable ids will first be the element 'test 1', do whatever is inside the for loop (i.e., send message to the person that is called 'test 1'. Then ids becomes 'test2', and a message is sent to 'test2'. But you try sending a message to the list of people, not the person picked (ids). I assume that the function send_direct_message does not allow lists, so therefore you need to have your third line be api.send_direct_message(ids, text).

CodePudding user response:

Why not use TRY and then EXCEPT for the relevant class?

You can then use PASS to do nothing and continue to the next.

  • Related