I have this code:
"'{}'".format(u'ES SIOUF_1')
When run in Python 2, I receive the following error:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 2: ordinal not in range(128)
The same code run from Python 3, gives:
>>> "'ES\xa0SIOUF_1'"
I don't need neither. What I would need is:
>>> "'ES SIOUF_1'"
I read many questions regarding "encoding" and "decoding" characters in Python, and some differences to this regard between Python 2 and 3.
However, I sincerely don't understand them and I'd like to solve this problem for both version of Python possibly.
The thing I've noticed is that doing:
type(u'ES SIOUF_1')
gives:
>>> <type 'unicode'> # PYTHON 2
>>> <class 'str'> # PYTHON 3