Python: UnicodeEncodeError: ‘ascii’ codec can’t encode character…

Developers like python because it is a fast way to develop scripts to make life easier. This is a fact on Linux, but sometimes you are forced to use Micr$s$ft. With this force comes the encoding fact Ascii. This will cause UnicodeEncodingErrors when the developer tries to print to stout. Below a small piece of code to help those who are forced to use Windows.

  import sys
  import codecs
  # Wrap sys.stdout with a writer that knows how to handle encoding
  wrapped_stdout = codecs.getwriter('UTF-8')(sys.stdout)
  # Replace sys.stdout with the writer
  sys.stdout = wrapped_stdout</blockquote>
Previous Post
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: