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
'.*
').
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.