I get a weird problem with __future__.unicode_literals
in Python. Without importing unicode_literals
I get the correct output:
# encoding: utf-8
# from __future__ import unicode_literals
name = 'helló wörld from example'
print name
But when I add the unicode_literals
import:
# encoding: utf-8
from __future__ import unicode_literals
name = 'helló wörld from example'
print name
I got this error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 4: ordinal not in range(128)
Does unicode_literals
encode every string as an utf-8?
What should I do to override this error?
See also: Python, Unicode, and the Windows console for a related, Windows-specific problem.