What determines how "at most size bytes are read and returned" with Python read()?
<p>In the documentation for Python's input/output, it states under Reading and Writing Files:</p>

<p><a href="https://docs.python.org/3.5/tutorial/inputoutput.html#methods-of-file-objects" rel="nofollow">https://docs.python.org/3.5/tutorial/inputoutput.html#methods-of-file-objects</a></p>

<p>"When size is omitted or negative, the entire contents of the file will be read and returned; itâs your problem if the file is twice as large as your machineâs memory. Otherwise, at most size bytes are read and returned."</p>

<p>Let's take the following code: </p>

<pre><code>size = 1000
with open('file.txt', 'r') as f:
    while True:
        read_data = f.read(size)
        if not read_data:
            break 
        print(read_data)   # outputs data in sizes equal to at most 1000 bytes
</code></pre>

<p>Here, <code>size</code> is at most 1000 bytes. What determines "at most"? </p>

<p>Let's say we are parsing rows of structured data. Each row is 750 bytes. Would read "cut off" the next row, or stop at the <code>\n</code>?</p>

<p><code>read</code> is not <code>readline</code> or <code>readlines</code>. It just reads bytes regardless of the file content (apart from the end of line translation since your file is open as text)</p>

<ul>
<li>If there's 1000 bytes to be read in the buffer, it returns 1000 bytes (or less if file has <code>\r\n</code> format (Windows CR+LF) and read as text, the <code>\r</code> chars are stripped)</li>
<li>If there's 700 bytes left, it returns 700 bytes (give or take the <code>\r</code> issue)</li>
<li>If there's nothing to read, it returns an empty buffer (<code>len(read_data)==0</code>).</li>
</ul>

python file input chunking