'Open the file in text mode, write to it, and close the file.'

def write_text(self, data, encoding=None, errors=None):

    if (not isinstance(data, str)):
        raise TypeError(('data    must    be    str,    not    %s' % data.__class__.__name__))
    with self.open(mode='w', encoding=encoding, errors=errors) as f:
        return f.write(data)
