◐ Shell
clean mode source ↗

Message 379957 - Python tracker

Another test case:

import tempfile
import io
import json


with tempfile.SpooledTemporaryFile(max_size=2**20) as f:
    tf = io.TextIOWrapper(f, encoding='utf-8')
    json.dump({}, fp=tf)

I was writing json to a file-like object that I need to read in as binary (to upload to S3). Originally the code used BytesIO and I thought it would be wise to actually spool this to disk as I was operating with possible limited RAM... except that of course it didn't work.