<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def open(cls, fp):
 """ Open a PSD document. :param fp: filename or file-like object. :return: A :py:class:`~psd_tools.api.psd_image.PSDImage` object. """

        if hasattr(fp, 'read'):
            self = cls(PSD.read(fp))
        else:
            with open(fp, 'rb') as f:
                self = cls(PSD.read(f))
        return self