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')
| 189 | |
| 190 | |
| 191 | def 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 |
| 214 | def atomic_writing(*args, **kwargs): |