obspy.core.util.base.NamedTemporaryFile

NamedTemporaryFile(dir=None, suffix='.tmp')[source]

Weak replacement for the Python’s tempfile.TemporaryFile.

This function is a replacment for tempfile.NamedTemporaryFile() but will work also with Windows 7/Vista’s UAC.

Parameters:
  • dir (str) If specified, the file will be created in that directory, otherwise the default directory for temporary files is used.
  • suffix (str) The temporary file name will end with that suffix. Defaults to '.tmp'.

Warning

Caller is responsible for deleting the file when done with it.

Example

>>> ntf = NamedTemporaryFile()
>>> ntf._fileobj  
<open file '<fdopen>', mode 'w+b' at 0x...>
>>> ntf._fileobj.close()
>>> os.remove(ntf.name)
>>> filename = NamedTemporaryFile().name
>>> fh = open(filename, 'wb')
>>> fh.write("test")
>>> fh.close()
>>> os.remove(filename)

This Page