Is this a bug in the windows

"Martin v. Löwis" martin at
Thu Sep 16 08:48:31 CEST 2004

Jonathan Wright wrote:
> Is there (and if not, should there be) any way to determine if an
> object is file-like?
> Or is this getting into protocol-oriented programming. :-)

I think so. You just use the object, e.g. invoke .read on it - if
that gives an AttributeError, you don't have a file-like object.
Of course, you should *know* that this is supposed to be a
file-like object in advance - otherwise, you wouldn't try to check
whether it is. So just use it as a file-like object, and don't
bother handling the exception, unless there is a clear strategy
what to do if the object is not file-like.


More information about the Python-list mailing list