On Fri, 4 Mar 2022 at 12:10, Christopher Barker <python...@gmail.com> wrote:
>
> On Thu, Mar 3, 2022 at 9:58 AM Kevin Mills <kevin.mills...@gmail.com> wrote:
>>
>> I actually initially was going to suggest a `strict` flag get added, but I 
>> figured that would be impractical. I was mostly concerned about classes that 
>> mimic file objects, because (obviously) their read methods wouldn't include 
>> a `strict` flag and you couldn't pass such objects to functions using the 
>> flag.
>
> you couldn't pass them to functions using a new method, either.
>
> No matter how you slice it, this would be an extension to the existing 
> file-like object "protocol"
>
> I use quotes because I don't think it's a clearly defined protocol.

For what it's worth, there IS a way to slice it that isn't an
extension. Create a separate function like this:

def read_chunk(f, size):
    data = f.read(size)
    while size >= len(data):
        data += f.read(size - len(data))
    return data

Stick that into os or something, and then it would work on anything
with a read method (and this has been deliberately written to not care
whether it's working in characters or bytes).

I think it's better as a method, but if there's an issue with
extending the protocol, this might be an alternative.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/CMWVOCW2TYZRD5AG2CUDLP4SAQQI3HDT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to