Expect() from telnetlib giving me problems.

Hans Nowak wurmy at earthlink.net
Thu Sep 12 22:11:53 EDT 2002

Marc wrote:

>   File "C:\python22\lib\telnetlib.py", line 541, in expect
>     list[i] = re.compile(list[i])
>   File "C:\Python22\lib\sre.py", line 178, in compile
>     return _compile(pattern, flags)
>   File "C:\Python22\lib\sre.py", line 228, in _compile
>     raise error, v # invalid expression
> error: nothing to repeat

Note that this is an error in sre.py, not in telnetlib. (A clue! ;-)

> I've tried several different ways to get the expect command to work. I
> can't find any examples and only limited documentation. Here is how
> I'm trying to implement it:
>     alist = [ 'COMPLD', '*/' ]
>     buffer = conn.expect(alist, 5)
> Can someone please tell me what is wrong or provide me with some
> working examples of using the command.

expect() expects a list of regular expressions. '*/' probably isn't a valid 
regex. See also


expect(list[, timeout])

Read until one from a list of a regular expressions matches.

The first argument is a list of regular expressions, either compiled 
(re.RegexObject instances) or uncompiled (strings). The optional second 
argument is a timeout, in seconds; the default is to block indefinitely.


Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/
Kaa:: http://www.awaretek.com/nowak/kaa.html

More information about the Python-list mailing list