code: def write_out(fil, msg):
      # XXX sometimes "msg" is of type bytes, sometimes text which
      # complicates the situation.  Should we try to enforce unicode?
      try:
          # on py27 and above writing out to sys.stdout with an encoding
          # should usually work for unicode messages (if the encoding is
          # capable of it)
          fil.write(msg)
      except UnicodeEncodeError:
          # on py26 it might not work because stdout expects bytes
          if fil.encoding:
              try:
                  fil.write(msg.encode(fil.encoding))
              except UnicodeEncodeError:
                  # it might still fail if the encoding is not capable
                  pass
              else:
                  fil.flush()
                  return
          # fallback: escape all unicode characters
          msg = msg.encode("unicode-escape").decode("ascii")
          fil.write(msg)
      fil.flush()
  
imports: import sys, os, unicodedata
  import py
  from py.builtin import text, bytes
label_desc: Use image node_id 6 for calling a global function with example usage: write_out(fil, msg) without return types