(no title)
DemetriousJones | 1 year ago
I understand if statements not having their own scope for simplicity's sake, but the fact that `with` blocks don't is simply mind-bobbling to me. ``` with open("text.txt", 'w') as f: f.write("hello world") f.write("hello world") # at least the handle was automatically closed so it will give an IO error ```
orf|1 year ago
One example would be a timing context manager:
Another example is mocks, where you want to inspect how many times a mock was called and with what arguments, after the mock context manager has finished.DemetriousJones|1 year ago
neongreen|1 year ago
DemetriousJones|1 year ago