Negative block sizes with file-like objects

Steven D'Aprano steve at
Sat Sep 27 09:02:27 CEST 2008

I have a proxy class that wraps an arbitrary file-like object fp and 
reads blocks of data from it. Is it safe to assume that will 
read until EOF? I know that's true for and, 
but is it a reasonable assumption to make for arbitrary file-like objects?

To put it in more concrete terms, I have a class like this:

class C(object):
    # Much simplified version.
    def __init__(self, fp):
        self.fp = fp
    def read(self, size=-1):

Should I re-write the read() method like this?

    def read(self, size=-1):
        if size < 0:


More information about the Python-list mailing list