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
close
Flush and close the IO object. 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
Read and return up to n bytes. 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
readinto1
readline
Read and return a line from the stream. readlines
Return a list of lines from the stream. seek
Change stream position. seekable
Return whether object supports random access. tell
Return current stream position. truncate
Truncate file to size bytes. writable
Return whether object was opened for writing. write
Write the given buffer to the IO stream. writelines
Private Methods
Warning
Private methods are mainly for internal/developer use and their API might change without notice.
_checkClosed
_checkReadable
_checkSeekable
_checkWritable
Special Methods
__dir__
Default dir() implementation. __enter__
__exit__
__format__
Default object formatter. __init__
Initialize self. __init_subclass__
This method is called when a class is subclassed. __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().