[Python-ideas] collections.abc.Stream

Chris Angelico rosuav at gmail.com
Sat Jun 18 14:53:05 EDT 2016


On Sat, Jun 18, 2016 at 10:16 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> But that's the whole point -- there is no one standard set of required
> methods. Some uses of a "file-like object" just require a read() or
> write() method. Some might require a close() method, or a flush(),
> or both. Some might need seek() and/or tell(). There's very little point
> in insisting on the full interface provided by open(...) if all you need
> is to call the write() method.

So then the question is: What can I provide to something which wants a
"file-like object"? Is an io.StringIO valid for this function, or for
that function? It's the most file-like non-file that I can think of,
so I'd generally expect it to work in most situations; it appears to
support a lot of operations. What about io.BytesIO? Right there, we
have to distinguish between "binary file-like objects" and "text
file-like objects". And with other classes, how do you know what you
need? The term "file-like object" is unfortunately made somewhat
useless by its variant uses.

ChrisA


More information about the Python-ideas mailing list