, , , , f.read() - , , , json.load() AttributeError, , read.
; hasattr/getattr:
def read(file_or_filename):
readfile = getattr(file_or_filename, 'read', None)
if readfile is not None:
return readfile()
with open(file_or_filename) as file:
return file.read()
, file_of_filename read, None, try/except over file_or_filename.read - : no parens, - , ElementTree._get_writer().
, , (io.RawIOBase.read(n) n > 0) (io.BufferedIOBase.write()) / ( io.TextIOBase), isinstance() ABC, io, , saxutils._gettextwriter() .