Skip to content

Instantly share code, notes, and snippets.

@davidwtbuxton
Created December 5, 2017 19:48
Show Gist options
  • Save davidwtbuxton/1ae338bab7833ae4a0b45936b4a3d5d3 to your computer and use it in GitHub Desktop.
Save davidwtbuxton/1ae338bab7833ae4a0b45936b4a3d5d3 to your computer and use it in GitHub Desktop.
python 2 string formatting fun
$ python2.7
Python 2.7.14 (default, Sep 22 2017, 00:06:07)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> value = u'\u0141uk\u0105\u015b\u017a'
>>> '%s' % value
u'\u0141uk\u0105\u015b\u017a'
>>> '{}'.format(value)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0141' in position 0: ordinal not in range(128)
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment