obspy.core.util.base.NamedTemporaryFile
- class NamedTemporaryFile(dir=None, suffix='.tmp', prefix='obspy-')[source]
Bases:
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
Public Methods
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, 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. |
|
Return whether object supports random access. |
|
Truncate file to size bytes. |
|
Return whether object was opened for writing. |
|
Write a list of lines to stream. |
Private Methods
Warning
Private methods are mainly for internal/developer use and their API might change without notice.
- NamedTemporaryFile._checkClosed()
- NamedTemporaryFile._checkReadable()
- NamedTemporaryFile._checkSeekable()
- NamedTemporaryFile._checkWritable()
Special Methods
- NamedTemporaryFile.__del__()
- NamedTemporaryFile.__delattr__(name, /)
Implement delattr(self, name).
- NamedTemporaryFile.__dir__()
Default dir() implementation.
- NamedTemporaryFile.__eq__(value, /)
Return self==value.
- NamedTemporaryFile.__format__(format_spec, /)
Default object formatter.
- NamedTemporaryFile.__ge__(value, /)
Return self>=value.
- NamedTemporaryFile.__getattribute__(name, /)
Return getattr(self, name).
- NamedTemporaryFile.__gt__(value, /)
Return self>value.
- NamedTemporaryFile.__hash__()
Return hash(self).
- NamedTemporaryFile.__init_subclass__()
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
- NamedTemporaryFile.__iter__()
Implement iter(self).
- NamedTemporaryFile.__le__(value, /)
Return self<=value.
- NamedTemporaryFile.__lt__(value, /)
Return self<value.
- NamedTemporaryFile.__ne__(value, /)
Return self!=value.
- NamedTemporaryFile.__new__(**kwargs)
- NamedTemporaryFile.__next__()
Implement next(self).
- NamedTemporaryFile.__reduce__()
Helper for pickle.
- NamedTemporaryFile.__reduce_ex__(protocol, /)
Helper for pickle.
- NamedTemporaryFile.__repr__()
Return repr(self).
- NamedTemporaryFile.__setattr__(name, value, /)
Implement setattr(self, name, value).
- NamedTemporaryFile.__sizeof__()
Size of object in memory, in bytes.
- NamedTemporaryFile.__str__()
Return str(self).
- NamedTemporaryFile.__subclasshook__()
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).