def mktempfile(self, data=None, prefix='ipython_edit_'):
    'Make a new tempfile and return its filename.\n\n        This makes a call to tempfile.mkstemp (created in a tempfile.mkdtemp),\n        but it registers the created filename internally so ipython cleans it up\n        at exit time.\n\n        Optional inputs:\n\n          - data(None): if data is given, it gets written out to the temp file\n            immediately, and the file is closed again.'
    dir_path = Path(tempfile.mkdtemp(prefix=prefix))
    self.tempdirs.append(dir_path)
    (handle, filename) = tempfile.mkstemp('.py', prefix, dir=str(dir_path))
    os.close(handle)
    file_path = Path(filename)
    self.tempfiles.append(file_path)
    if data:
        file_path.write_text(data, encoding='utf-8')
    return filename
Make a new tempfile and return its filename.

This makes a call to tempfile.mkstemp (created in a tempfile.mkdtemp),
but it registers the created filename internally so ipython cleans it up
at exit time.

Optional inputs:

  - data(None): if data is given, it gets written out to the temp file
    immediately, and the file is closed again.
def mktempfile(self, data=None, prefix='ipython_edit_'):
    'Make a new tempfile and return its filename.\n\n        This makes a call to tempfile.mkstemp (created in a tempfile.mkdtemp),\n        but it registers the created filename internally so ipython cleans it up\n        at exit time.\n\n        Optional inputs:\n\n          - data(None): if data is given, it gets written out to the temp file\n            immediately, and the file is closed again.'
    dir_path = Path(tempfile.mkdtemp(prefix=prefix))
    self.tempdirs.append(dir_path)
    (handle, filename) = tempfile.mkstemp('.py', prefix, dir=str(dir_path))
    os.close(handle)
    file_path = Path(filename)
    self.tempfiles.append(file_path)
    if data:
        file_path.write_text(data, encoding='utf-8')
    return filename