3 ms·
In JS, we could do: open('file', (myfile) => process(myfile.read())) It would be on the implementer of `open` to call `file.close()`, but presumably that'
by akavi 3y ago
In JS, we could do:
open('file', (myfile) => process(myfile.read()))
It would be on the implementer of `open` to call `file.close()`, but presumably that's true of python as well?
- kstrauser 3y agoI think so, depending on how I'm reading your definition of "the implementer". If you meant "the code that implements the open() context manager", then yes. It looks something like: def open_context_manager(filename): try: f = open(filename) yield f finally: f.close()