Skip to content

Instantly share code, notes, and snippets.

@mbylstra
Last active December 22, 2015 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbylstra/6448401 to your computer and use it in GitHub Desktop.
Save mbylstra/6448401 to your computer and use it in GitHub Desktop.
#modified version off http://code.activestate.com/recipes/576602-safe-print/
def sprint(*args, **kwargs):
"""Safely print the given string.
If you want to see the code points for unprintable characters then you
can use `errors="xmlcharrefreplace"`.
"""
errors = kwargs.get('errors', 'replace')
for s in args:
s = s.encode(sys.stdout.encoding or "utf-8", errors)
print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment