import tempfile with tempfile.TemporaryDirectory() as tmpdirname: print('Created temporary directory:', tmpdirname) # Both the directory and its contents have been deleted