r/Python • • Nov 25 '22

Intermediate Showcase defer in python!

https://github.com/dankeyy/defer.py

stupid but works lol hope you like it

303 Upvotes

62 comments sorted by

View all comments

Show parent comment

2

u/fiedzia Nov 25 '22

Python has context managers for that:

with open('file.txt') as f: #do stuff #when done f will be closed by context manager