I've found that using this construction has basically eliminated Unicode errors for me:
Code: Select all
u"Something interesting: {0}".format(some_var)
But that doesn't always work:
Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-
some_var = 'º'
print(u"Something interesting: {0}".format(some_var))
Yields:
Code: Select all
Traceback (most recent call last):
File "untitled text 136", line 5, in <module>
print(u"Something interesting: {0}".format(some_var))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal not in range(128)
So you can do this:
Code: Select all
some_var = 'º'
print(u"Something interesting: {0}".format(some_var.decode('utf-8')))
Which yields:
Code: Select all
================================================================================
Apr 19, 2018, 6:47:03 AM
untitled text 136
--------------------------------------------------------------------------------
Something interesting: º
So I *think* you'll need to trap on the error and decode the string when needed.
Unicode is a pain.