MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/z4aic2/defer_in_python/ixqi8a4/
r/Python • u/dankey26 • Nov 25 '22
https://github.com/dankeyy/defer.py
stupid but works lol hope you like it
62 comments sorted by
View all comments
Show parent comment
20
Python has both with and finally statements though, so there's little need for it here. (But cool metaprogramming trick.)
4 u/james_pic Nov 25 '22 It is occasionally useful, if you need to close a large or variable number of things in a block of code. Fortunately, contextlib.ExitStack is already in the stdlib and is a less evil way to do this.
4
It is occasionally useful, if you need to close a large or variable number of things in a block of code. Fortunately, contextlib.ExitStack is already in the stdlib and is a less evil way to do this.
contextlib.ExitStack
View all comments
Show parent comment
20
u/caagr98 Nov 25 '22
Python has both with and finally statements though, so there's little need for it here. (But cool metaprogramming trick.)