code: def redirect(target, file=sys.stderr):
      """Replication of ``redirect_stderr`` or ``redirect_stdout``.
  
      :source: http://stackoverflow.com/questions/4675728/redirect-stdout-to-a-file-in-python/22434262#22434262
      """
      original, file = file, target
  
      try:
          yield target
      finally:
          file = original
  
imports: import os
  import stat
  import sys
  from contextlib import contextmanager
label_desc: Use image node_id 1 for calling a global function with example usage: redirect(target, file) without return types