Skip to content Skip to sidebar Skip to footer

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 trigger

Solution 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'matchelse: # i == 1
    # do something with 'second'match

For more: http://pexpect.readthedocs.org/en/stable/overview.html

Post a Comment for "Pexpect - Multiple Expects"