- class NamedTemporaryFile(dir=None, suffix='.tmp', prefix='obspy-')¶
Weak replacement for the Python’s tempfile.TemporaryFile.
This class is a replacement for tempfile.NamedTemporaryFile() but will work also with Windows 7/Vista’s UAC.
>>> with NamedTemporaryFile() as tf: ... _ = tf.write(b"test") ... os.path.exists(tf.name) True >>> # when using the with statement, the file is deleted at the end: >>> os.path.exists(tf.name) False
>>> with NamedTemporaryFile() as tf: ... filename = tf.name ... with open(filename, 'wb') as fh: ... _ = fh.write(b"just a test") ... with open(filename, 'r') as fh: ... print(fh.read()) just a test >>> # when using the with statement, the file is deleted at the end: >>> os.path.exists(tf.name) False
__abstractmethods__ frozenset() -> empty frozenset object __dict__ __doc__ str(object=’‘) -> str __module__ str(object=’‘) -> str closed
close detach Disconnect this buffer from its underlying raw stream and return it. fileno Returns underlying file descriptor if one exists. flush Flush write buffers, if applicable. isatty Return whether this is an ‘interactive’ stream. read read1 Read and return up to n bytes, with at most one read() call to the underlying raw stream. readable Return whether object was opened for reading. readinto readline Read and return a line from the stream. readlines Return a list of lines from the stream. seek seekable Return whether object supports random access. tell truncate Truncate file to size bytes. writable Return whether object was opened for writing. write writelines
Private methods are mainly for internal/developer use and their API might change without notice.
_checkClosed _checkReadable _checkSeekable _checkWritable
__dir__ default dir() implementation __enter__ __exit__ __format__ default object formatter __init__ __new__ Create and return a new object. __reduce__ helper for pickle __reduce_ex__ helper for pickle __sizeof__ size of object in memory, in bytes __subclasshook__ Abstract classes can override this to customize issubclass().