如何逐行读取 "data" 属性? Python

How to read line by line for the "data" attribute ? Python

有人知道我如何逐行读取“数据”吗?。我的目标是逐行读取数据并在按下“发送”时将其发送到某个地方。目前我可以读取数据,但不能逐行读取。

我做了什么

    def mouseHover(event):
        x = lbox.curselection()[0]
        file = lbox.get(x)
        self.s.send(("fdown~" + file).encode("utf-8")) 
        self.s.recv(1024).decode("utf-8")

        self.s.send("OK".encode("utf-8"))
        open(file , 'wb+')  #must have
        global data
        data = (self.s.recv(1024).decode("utf-8") ) 
        sys.stdout.flush()
        self.text.insert(tk.END, data)
    lbox.bind("<<ListboxSelect>>", mouseHover)

可以这样做:

lines = [entry.strip() for entry in open("filename.txt", "r")]

for line in lines:
    [Do whatever]