[Tutor] telnetlib's read_very_eager() method?

Walter Prins wprins at gmail.com
Wed Sep 14 21:54:17 CEST 2011


On 14 September 2011 20:44, James Hartley <jjhartley at gmail.com> wrote:

> #!/usr/bin/env python
>
> import telnetlib
>
> if __name__ == '__main__':
>     print 'begin'
>     tn = telnetlib.Telnet('gmail-smtp-in.l.google.com', 25)
>     s = tn.read_very_eager()
>     print s
>     tn.write("helo\n")
>     s = tn.read_very_eager()
>     print s
>     tn.write("quit\n")
>     s = tn.read_very_eager()
>     print s
>     print 'end'
> $ python script.py
> begin
>
>
>
> end
> $
>
> What do I need to do to emulate the IDE environment?  If I am needing to
> capture stdout, it isn't readily apparent.
>

Make it go slower or force it to read *some* data at least.  Interactively
there's plenty of time for data to arrive for read_very_eager() to read.
When run as a batch your computer tries to read and continue before any
data's been returned from google.

Hence, try using read_some() instead of read_very_eager().

Aside: If you want to interact with a mail server there's probably better
modules to be using than the telnet module.

Walter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110914/52b1ad61/attachment.html>


More information about the Tutor mailing list