pexpect - multiple expects
问题 Is it possible to "wait" for different answers from an expect command at the same time? E.g: child.expect('first', 'second') And if YES, how can differentiate which one has triggered it? 回答1: Yes, you can do it like: i = child.expect(['first', 'second']) The expect() method returns the index of the pattern that was matched. So in your example: if i == 0: # do something with 'first' match else: # i == 1 # do something with 'second' match For more: http://pexpect.readthedocs.org/en/stable