Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Last active January 26, 2016 11:24
Show Gist options
  • Save kezabelle/9e271d20f296b04423d5 to your computer and use it in GitHub Desktop.
Save kezabelle/9e271d20f296b04423d5 to your computer and use it in GitHub Desktop.
Gods I hate you python string formatting
>>> x = u'\u2019'
>>> '%s' % x
u'\u2019'
>>> '%(x)s' % {'x': x}
u'\u2019'
>>> '{}'.format(x)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 0: ordinal not in range(128)
>>> {0!s}'.format(x)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' 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