SpooledTemporaryFile: units of maximum (in memory) size?

The max_size of tempfile.SpooledTemporaryFile() parameter is the maximum size of a temporary file that can fit in memory (before it is written to disk). What are the units of this parameter (bytes? Kilobytes?)? The documentation (for both Python 2.7 and Python 3.4 ) does not indicate this.

+6
source share
1 answer

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 the position in bytes.

I would say that any use of the term size in connection with Python file objects, not expressed in bytes, needs to be explicitly mentioned. All other file methods that deal with size always work in bytes.

+8
source

Source: https://habr.com/ru/post/984563/


All Articles