[Python-ideas] collections.abc.Stream

Michael Selik michael.selik at gmail.com
Fri Jun 17 10:38:14 EDT 2016


On Fri, Jun 17, 2016, 2:01 AM Ram Rachum <ram at rachum.com> wrote:

> Is there a way to check in Python whether an object is file-like? (Like
> `open`, `StringIO`, etc.) I would think that an abc in collections.abc will
> be the standard solution, like we have for so many other data types, but I
> can't find one.
>

File-like means different things in different places. Some functions want
the read method, others want readline.

How about just trying to use the method and catching AttributeError?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160617/47ec96b1/attachment.html>


More information about the Python-ideas mailing list