MCPcopy Create free account
hub / github.com/ipython/ipython / mktempfile

Method mktempfile

IPython/core/interactiveshell.py:3593–3615  ·  view source on GitHub ↗

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

(self, data=None, prefix='ipython_edit_')

Source from the content-addressed store, hash-verified

3591 return cmd
3592
3593 def mktempfile(self, data=None, prefix='ipython_edit_'):
3594 """Make a new tempfile and return its filename.
3595
3596 This makes a call to tempfile.mkstemp (created in a tempfile.mkdtemp),
3597 but it registers the created filename internally so ipython cleans it up
3598 at exit time.
3599
3600 Optional inputs:
3601
3602 - data(None): if data is given, it gets written out to the temp file
3603 immediately, and the file is closed again."""
3604
3605 dirname = tempfile.mkdtemp(prefix=prefix)
3606 self.tempdirs.append(dirname)
3607
3608 handle, filename = tempfile.mkstemp('.py', prefix, dir=dirname)
3609 os.close(handle) # On Windows, there can only be one open handle on a file
3610 self.tempfiles.append(filename)
3611
3612 if data:
3613 with open(filename, 'w') as tmp_file:
3614 tmp_file.write(data)
3615 return filename
3616
3617 @undoc
3618 def write(self,data):

Callers 4

test_mktempfileMethod · 0.80
_find_edit_targetMethod · 0.80
_edit_macroMethod · 0.80
editMethod · 0.80

Calls 2

closeMethod · 0.45
writeMethod · 0.45

Tested by 1

test_mktempfileMethod · 0.64