1. from tempfile import TemporaryFile
    2. with TemporaryFile('w+') as f:
    3. # Read/write to the file
    4. f.write('Hello World\n')
    5. f.write('Testing\n')
    6. # Seek back to beginning and read the data
    7. f.seek(0)
    8. data = f.read()
    9. print(data)
    10. from tempfile import TemporaryDirectory
    11. with TemporaryDirectory() as dirname:
    12. print(dirname)