code: def write_text(self, data, encoding=None, errors=None):
          
          if not isinstance(data, six.text_type):
              raise TypeError(
                  'data must be %s, not %s' %
                  (six.text_type.__class__.__name__, data.__class__.__name__))
          with self.open(mode='w', encoding=encoding, errors=errors) as f:
              return f.write(data)
docs: Open the file in text mode, write to it, and close the file.