⬅︎ Back to Go vs. Python
I've never seen try/finally used to mimic defer. The idiomatic python solution is a with block, a.k.a. a context manager, which I argue is superior to go's defer since you can achieve the deferral on the same line you're opening the file.with open("defer.py") as f: f.read()
Comment
I've never seen try/finally used to mimic defer. The idiomatic python solution is a with block, a.k.a. a context manager, which I argue is superior to go's defer since you can achieve the deferral on the same line you're opening the file.
with open("defer.py") as f:
f.read()