spock
6/10/2017 - 8:17 PM

Example for creating named temp files and dirs

from tempfile import NamedTempFile, TemporaryDirectory


with NamedTemporaryFile(suffix='.pdf') as tmp:
    # do your thing ...
  
  
with TemporaryDirectory() as dirpath:
    # do your thing ...
    
    
    
# tmp file/dir deleted after exiting context...