Question: I was looking at some code in Python (I know nothing about Python) and I came across this portion:

```
def do_req(body):
    global host, req
    data = ""
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host, 80))
    s.sendall(req % (len(body), body))
    tmpdata = s.recv(8192)
    while len(tmpdata) > 0:
        data += tmpdata
        tmpdata = s.recv(8192)
    s.close()
    return data

```

This is then called later on with body of huge size, as in over 500,000 bytes. This is sent to an Apache server that has the max request size on the default 8190 bytes. 

My question is what is happening at the "`s.sendall()`" part? Obviously the entire body cannot be sent at once and I'm guessing it is reduced by way of the modulus operator. I don't know how it works in Python, though. Can anyone explain? Thanks.

Answer: 
It is not really the modulus operator (technically it is since strings simply implement [`__mod__`](http://docs.python.org/reference/datamodel.html#object.__mod__)) but the [python2-style string formatting operator](http://docs.python.org/library/stdtypes.html#string-formatting-operations).

> 
> Given `format % values` (where *format* is a string or Unicode object), `%` conversion specifications in *format* are replaced with zero or more elements of *values*. The effect is similar to the using `sprintf()` in the C language. 
> 
> 
> 

> 
> Obviously the entire body cannot be sent at once
> 
> 
> 

While it indeed doesn't fit into a single packet that's a low-level thing which is handled internally (most likely not even by python but by the underlying syscall that writes to a socket)
No, body is not reduced here, because % is format operator, when operates on strings. 

<http://docs.python.org/release/2.5.2/lib/typesseq-strings.html>

All the data is sent by sendall method by parts.

socket.sendall works like that:

```
do {
        n = sendsegmented(s->sock_fd, buf, len, flags);
        len -= n;
} while (len > 0);

```

where sendsegmented sends data and returns len or SEGMENT\_SIZE