Advertisement
Ichimonji10

encoding a unicode string

Jun 22nd, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. >>> s = u'→é'
  2. >>> s.encode('utf-8')
  3. '\xe2\x86\x92\xc3\xa9'
  4. >>> s.encode('utf-16')
  5. '\xff\xfe\x92!\xe9\x00'
  6. >>> s.encode('ascii')
  7. Traceback (most recent call last):
  8.   File "<stdin>", line 1, in <module>
  9. UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement