obspy.core.util.base.NamedTemporaryFile¶
-
class
NamedTemporaryFile
(dir=None, suffix='.tmp', prefix='obspy-')[source]¶ Bases:
io.BufferedIOBase
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.- Parameters
Example
>>> 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
Attributes
__abstractmethods__
__dict__
__doc__
__module__
closed
Public Methods
Flush and close the IO object.
Disconnect this buffer from its underlying raw stream and return it.
Returns underlying file descriptor if one exists.
Flush write buffers, if applicable.
Return whether this is an ‘interactive’ stream.
Read and return up to n bytes.
Read and return up to n bytes, with at most one read() call to the underlying raw stream.
Return whether object was opened for reading.
Read and return a line from the stream.
Return a list of lines from the stream.
Change stream position.
Return whether object supports random access.
Return current stream position.
Truncate file to size bytes.
Return whether object was opened for writing.
Write the given buffer to the IO stream.
Private Methods
Warning
Private methods are mainly for internal/developer use and their API might change without notice.
Special Methods
Default dir() implementation.
Default object formatter.
Initialize self.
This method is called when a class is subclassed.
Create and return a new object.
Helper for pickle.
Helper for pickle.
Size of object in memory, in bytes.
Abstract classes can override this to customize issubclass().