<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(self, data):
 """ Write ``data`` to the file. :type data: bytes :param data: the data to be written to the file :rtype: int :return: the number of bytes written """

        _complain_ifclosed(self.closed)
        if self.__encoding:
            self.f.write(data.encode(self.__encoding, self.__errors))
            return len(data)
        else:
            return self.f.write(data)