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

Function temp_pyfile

IPython/utils/io.py:191–211  ·  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, ext='.py')

Source from the content-addressed store, hash-verified

189
190
191def temp_pyfile(src, ext='.py'):
192 """Make a temporary python file, return filename and filehandle.
193
194 Parameters
195 ----------
196 src : string or list of strings (no need for ending newlines if list)
197 Source code to be written to the file.
198
199 ext : optional, string
200 Extension for the generated file.
201
202 Returns
203 -------
204 (filename, open filehandle)
205 It is the caller's responsibility to close the open file and unlink it.
206 """
207 fname = tempfile.mkstemp(ext)[1]
208 with open(fname,'w') as f:
209 f.write(src)
210 f.flush()
211 return fname
212
213@undoc
214def atomic_writing(*args, **kwargs):

Callers 1

mktmpMethod · 0.90

Calls 2

writeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected