Skip to content

Latest commit

 

History

History
19 lines (13 loc) · 478 Bytes

String-Format-Unicode-params.md

File metadata and controls

19 lines (13 loc) · 478 Bytes
  • Date : 2015-12-01
  • Tags : #python #string #unicode

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)