August 2018
Intermediate to advanced
366 pages
10h 14m
English
Like the other tempfile object, creating SpooledTemporaryFile is enough to make the temporary file available. The only additional part is to provide the maximum allowed size, max_size=, after which the content will be moved to disk:
>>> with tempfile.SpooledTemporaryFile(max_size=30) as temp: ... for i in range(3): ... temp.write(b'Line of text\n') ... ... temp.seek(0) ... print(temp.read()) ... b'Line of text\nLine of text\nLine of text\n'