def __is_or_has_file(self, data):
'''
Figure out if we have been given a file-like object as one of the inputs to the function that called this.
Is a bit clunky because 'file' doesn't exist as a bare-word type check in Python 3 and built in file objects
are not instances of io.<anything> in Python 2
https://stackoverflow.com/questions/1661262/check-if-object-is-file-like-in-python
Returns:
Boolean - True if we have a file-like object
'''
if (hasattr(data, 'file')):
data = data.file
try:
return isinstance(data, file)
except NameError:
from io import IOBase
return isinstance(data, IOBase)
评论列表
文章目录