code: def open_file_like(f, mode):
      
      new_fd = isinstance(f, (str, pathlib.Path))
      if new_fd:
          f = open(f, mode)
      try:
          yield f
      finally:
          if new_fd:
              f.close()
docs: Wrapper for opening a file