Lets take a simple variable -
var = u' \u2013 2'
Lets try decoding it -
var.decode('utf-8')
I get the following error -
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 7: ordinal not in range(128)
Lets try encoding it -
var.encode('utf-8')
I get the following error -
'ascii' codec can't decode byte 0xe2 in position 8: ordinal not in range(128)
One solution is to do -
sys.setdefaultencoding('utf-8')
Let me know, what others are doing?
unicodeandbytes. Python 27 did not manage to get it right however: unicode objects have a.decodemethod, and bytestrings have a.encodewhich is a non sense.