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

时间:2019-02-04 21:10:20

标签: python string parsing telnet

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

“ T H 一世 s ...” 依此类推。

  override func viewDidLoad() {
super.viewDidLoad()

collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "MYIDENTIFIER")

let myDataSource = MyDataSource(). //See the problem here?
collectionView.delegate = myDataSource
collectionView.dataSource = myDataSource

} //myDataSource will be released!

1 个答案:

答案 0 :(得分:0)

如果我正确回答了您的问题,它应该看起来像这样:

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的评论更新了答案。

相关问题