Now I learn about network programming. I wanted to write myself a recvall function. My messages are sent through a TCP sockets and always end with the \r\n. Googling some articles and blog posts, I found a method I do not understand. Can it be written simpler?
def recvuntil(s, needle):
    data = ""
    while data[-len(needle):] != needle:
        data += s.recv(1)
    return data
The line I do not understand: while data[-len(needle):] != needle:.  It does not make any sense to me (but, however, it works). -len(needle) should return a negative number and strings are numbered starting from 0 ... 
 
     
     
     
    