Reputation: 1108
How can I work with pexpect when the "expect" is not fixed:
Example: +DTMF: X
, where X
could be any integer from 0 to 9, such as +DTMF: 1
.
I tried this but not success:
self.child.expect('+DTMF:', timeout=1)
Upvotes: 0
Views: 1725
Reputation: 105
I had a similar issue recently. Since the numbers at the end were important for me I found out that you could parse them by running those two lines.
child.expect('+DTFM: ')
value = child.read(1)
I assumed that you only had one digit, but you can specify the number of expected character on the child.read function.
Otherwise using regex will yield a more exact expect statement.
Upvotes: 0
Reputation: 1450
pexpect uses regular expressions, you can do this:
self.child.expect('\+DTMF: [0-9]', timeout=1)
Upvotes: 3