Python: I do not understand this syntax : <p>Now I learn about network programming. I wanted to write myself a <code>recvall</code> function. My messages are sent through a TCP sockets and always end with the <code>\r\n</code>. Googling some articles and blog posts, I found a method I do not understand. Can it be written simpler?</p>

<pre><code>def recvuntil(s, needle):
    data = ""
    while data[-len(needle):] != needle:
        data += s.recv(1)
    return data
</code></pre>

<p>The line I do not understand: <code>while data[-len(needle):] != needle:</code>.  It does not make any sense to me (but, however, it works). <code>-len(needle)</code> should return a negative number and strings are numbered starting from <code>0</code> ... </p>
