Calmcode - context managers: utilities

Building a context manager from scratch.

1 2 3 4 5 6
with open("file.txt") as f:
    lines = f.read()

lines.split("\n")
import tempfile

with tempfile.TemporaryDirectory() as tempdir_path:
    print(f'I have a temporary directory at: {tempdir_path}')

with tempfile.TemporaryFile(mode='w+') as file:
    file.write('hello, world')
    file.seek(0)
    print(file.readlines())