def _safe_print(u, errors="replace"): """Safely print the given string. If you want to see the code points for unprintable characters then you can use `errors="xmlcharrefreplace"`. """ s = u.encode(sys.stdout.encoding or "utf-8", errors) print(s)