pexpect - multiple expects

我是研究僧i 提交于 2020-01-24 12:13:12

问题


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/overview.html



来源:https://stackoverflow.com/questions/35132976/pexpect-multiple-expects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!