code: def safe_str(u, errors="replace"):
      
      s = u.encode(sys.stdout.encoding or "utf-8", errors)
      return s
docs: Safely print the given string.
  
      If you want to see the code points for unprintable characters then you
      can use `errors="xmlcharrefreplace"`.
      http://code.activestate.com/recipes/576602-safe-print/