#til

#TIL : String Format Unicode params

unicode_thing = u"Xin chào mọi người"
a = '{}'.format(unicode_thing)

will cause the error UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 6: ordinal not in range(128)

The solution is add u prefix the pattern (it means using unicode pattern) :

unicode_thing = u"Xin chào mọi người"
a = u'{}'.format(unicode_thing)

Enjoyed this post?

If you found this helpful, consider sharing it or leaving a kudo!

0 kudos