<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_editor(self, data=''):
 """ Open a file for editing using the system's default editor. After the file has been altered, the text will be read back and the HTML comment tag <!--INSRUCTIONS --> will be stripped. If an error occurs inside of the context manager, the file will be preserved so users can recover their data. Otherwise, the file will be deleted when the context manager closes. Params: data (str):
 If provided, text will be written to the file before opening it with the editor. Returns: text (str):
 The text that the user entered into the editor. """


        with NamedTemporaryFile(prefix='rtv_', suffix='.txt', delete=False) as fp:
            # Create a tempory file and grab the name, but close immediately so
            # we can re-open using the right encoding
            filepath = fp.name

        with codecs.open(filepath, 'w', 'utf-8') as fp:
            fp.write(data)
        _logger.info('File created: %s', filepath)

        editor = (os.getenv('RTV_EDITOR') or
                  os.getenv('VISUAL') or
                  os.getenv('EDITOR') or
                  'nano')
        command = shlex.split(editor) + [filepath]
        try:
            with self.suspend():
                _logger.debug('Running command: %s', command)
                p = subprocess.Popen(command)
                try:
                    p.communicate()
                except KeyboardInterrupt:
                    p.terminate()
        except OSError as e:
            _logger.exception(e)
            self.show_notification('Could not open file with %s' % editor)

        with codecs.open(filepath, 'r', 'utf-8') as fp:
            text = fp.read()
            text = self.strip_instructions(text)

        try:
            yield text
        except exceptions.TemporaryFileError:
            # All exceptions will cause the file to *not* be removed, but these
            # ones should also be swallowed
            _logger.info('Caught TemporaryFileError')
            self.show_notification('Post saved as: %s' % filepath)
        else:
            # If no errors occurred, try to remove the file
            try:
                os.remove(filepath)
            except OSError:
                _logger.warning('Could not delete: %s', filepath)
            else:
                _logger.info('File deleted: %s', filepath)