Demo entry 6638329

desc

   

Submitted by anonymous on Sep 07, 2017 at 12:49
Language: Python. Code size: 832 Bytes.

Python 2.7.13 (default, Apr  4 2017, 08:47:57) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> data = u'\u00c3'
>>> data = data.encode('utf8')  # encoded to UTF-8
>>> data
'\xc3\x83'
>>> data.encode('utf8')         # Try to *re*-encode it
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
>>> 
>>> # Fix the above issue
... 
>>> import sys  
>>> reload(sys)  
<module 'sys' (built-in)>
>>> sys.setdefaultencoding('utf8')
>>> data = u'\u00c3'
>>> data = data.encode('utf8')  # encoded to UTF-8
>>> data
'\xc3\x83'
>>> data.encode('utf8')         # Try to *re*-encode it
'\xc3\x83'
>>> 

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).