code: def open_temporarily(
      path, mode, delete_parent_if_empty: bool = False
  ):
      parentDir = Path(path).parent
      parentDir.mkdir(parents=True, exist_ok=True)
  
      file = open(path, mode)
  
      try:
          yield file
      finally:
          file.close()
          os.remove(path)
          if (
              delete_parent_if_empty
              and len(os.listdir(str(parentDir))) == 0
          ):
              shutil.rmtree(str(parentDir))
  
imports: import os
  import shutil
  from contextlib import contextmanager
  from pathlib import Path
label_desc: Use image node_id 2 for calling a global function with example usage: open_temporarily(path, mode, delete_parent_if_empty) without return types