MCPcopy Index your code
hub / github.com/ipython/ipython / temp_pyfile

Function temp_pyfile

IPython/utils/io.py:118–137  ·  view source on GitHub ↗

Make a temporary python file, return filename and filehandle. Parameters ---------- src : string or list of strings (no need for ending newlines if list) Source code to be written to the file. ext : optional, string Extension for the generated file. Returns

(src: str, ext: str='.py')

Source from the content-addressed store, hash-verified

116
117
118def temp_pyfile(src: str, ext: str='.py') -> str:
119 """Make a temporary python file, return filename and filehandle.
120
121 Parameters
122 ----------
123 src : string or list of strings (no need for ending newlines if list)
124 Source code to be written to the file.
125 ext : optional, string
126 Extension for the generated file.
127
128 Returns
129 -------
130 (filename, open filehandle)
131 It is the caller's responsibility to close the open file and unlink it.
132 """
133 fname = tempfile.mkstemp(ext)[1]
134 with open(Path(fname), "w", encoding="utf-8") as f:
135 f.write(src)
136 f.flush()
137 return fname

Callers 1

mktmpMethod · 0.90

Calls 2

writeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…