The parameter max_size
of tempfile.SpooledTemporaryFile()
is the maximum size of the temporary file that can fit in memory (before it is spilled to disk). What are the units of this parameter (bytes? kilobytes?)? The documentation (both for Python 2.7 and Python 3.4) does not indicate this.
Tempfile is a Python module used in a situation, where we need to read multiple files, change or access the data in the file, and gives output files based on the result of processed data. Each of the output files produced during the program execution was no longer needed after the program was done.
The directory named by the TEMP environment variable. The directory named by the TMP environment variable. A platform-specific location: On Windows, the directories C:\TEMP , C:\TMP , \TEMP , and \TMP , in that order.
import tempfile # create a temporary directory using the context manager with tempfile. TemporaryDirectory() as tmpdirname: print('created temporary directory', tmpdirname) # Outside the context manager, directory and contents have been removed.
The size is in bytes. From the SpooledTemporaryFile()
source code:
def _check(self, file):
if self._rolled: return
max_size = self._max_size
if max_size and file.tell() > max_size:
self.rollover()
and file.tell()
gives a position in bytes.
I'd say that any use of the term size
in connection with Python file objects that is not expressed in bytes warrants an explicit mention. All other file methods that deal in terms of size
always work in bytes as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With