Name
expect
Synopsis
t.expect(res,timeout=None)Reads data from the connection until it matches any of the regular
expressions that are the items of list
res, or until
timeout seconds elapse when
timeout is not None.
Regular expressions and match objects are covered in Chapter 9. Returns a tuple of three items
(
i,mo,txt
),
where i is the index in
res of the regular expression that
matched, mo is the match object, and
txt is all the text read until the match,
included. Raises EOFError when the connection is
closed and no data is available; otherwise, when it gets no match,
returns
(-1,None,txt
),
where txt is all the text read, or
possibly '' if nothing was read before a timeout.
Results are non-deterministic if more than one item in
res can match, or if any of the items in
res include greedy parts (such as
'.*').
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access