Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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?


I 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()




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: