Telnet
Chris Liechti
cliechti at gmx.net
Thu Mar 21 17:56:17 EST 2002
"Billy Ng" <evebill8 at hotmail.com> wrote in news:d4tm8.2110$oi.93984
@newsread2.prod.itd.earthlink.net:
> Thanks! "\r\n" is the key. It works after I added into the write
> (). functon
>
> Okay, now I have 2 more questions.
>
> 1) How can I save the returned data into a list? I tried to use
> the read_all() function, but it just stops there.
>
> tn.read_until("ending line")
> lines = []
> lines = tn.read_all()
this simply replaces the list you bound to "lines" with a string
containig all the data.
read_all() will block until the other side closes the connection. if
you can send a "quit","exit" or "logout"command to the other side it
might hang up, so that this works but that depends on your server.
> 2) I was also trying to do this,
>
> tn.read_until("beginnig line to grap")
> lines = []
> lines = tn.read_until("ending line")
same note as above
> for line in lines
> print line
>
> But it prints one character in each line
yes, as "type(lines)" will point out its now a string and not a list
bound to the name "lines"
i don't see a method to read by lines in telnetlib. but you can do
(untested):
import cStringIO
memfile = cStringIO.StringIO(tn.read_until("ending line"))
for line in memfile.readlines():
print line
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list