code: def get_file_handle_save(path, ext):
      if ext == ".nnp":
          need_close = True
          f = zipfile.ZipFile(path, "w")
      elif ext == ".h5":
          need_close = True
          f = h5py.File(path, "w")
      elif ext in [".nntxt", ".prototxt"]:
          if hasattr(path, "read"):
              need_close = False
              f = path
          else:
              need_close = True
              f = open(path, "w")
      elif ext == ".protobuf":
          if hasattr(path, "read"):
              need_close = False
              f = path
          else:
              need_close = True
              f = open(path, "wb")
      else:
          raise ValueError(
              "Currently, ext == {} is not support".format(ext)
          )
      try:
          yield f
      finally:
          if need_close:
              f.close()
          if hasattr(path, "seek"):
              path.seek(0)
  
imports: import contextlib
  import io
  import os
  import re
  import zipfile
  from collections import OrderedDict
  from functools import partial
  import google.protobuf.text_format
  import h5py
  import nnabla
  import numpy
  from nnabla.logger import logger
  from nnabla.utils import nnabla_pb2
  from nnabla.utils.nnp_format import nnp_version
label_desc: Use image node_id 2 for calling a global function with example usage: get_file_handle_save(path, ext) without return types