逐行解析Telnet.Read_Very_Eager返回的字符串

Parsing string returned by Telnet.Read_Very_Eager line by line

在python中,如何将其解析为字符串? 我希望输出打印每一行,行由换行符 (\n) 分隔符找到,但我得到的只是单个字符,例如,如果服务器发送“这是一个字符串 这是另一个”我得到

"T H 一世 秒 ……” 等等。

from time import sleep
tn = Telnet('myhost',port)
sleep(0.5)
response = tn.read_very_eager()

#How do I do something like this? I tried parsing it using string.split,
#all I got was individual characters.
foreach (line in response):
    print line, "This is a new line"

tn.close()

foreach (line in response):
    print line, "This is a new line"


如果我答对了你的问题,它应该是这样的:

from time import sleep

tn = Telnet('myhost', port)
sleep(0.5)

response = tn.read_very_eager()

for line in response.split():
    # Python 3.x version print
    print(line)

    # Python 2.x version print
    # print line

tn.close()

UPD:根据 OP 的评论更新了答案。