python 2.7 -remove backslash from unicode

Question:

I have this unicode

xx = u"Merci d'avoir acheté Electricité mobile, votre SPS sera activé prochainement"

when i print it it looks ok
when i want to compare this xx the unicode appears like this

u'Merci d'avoir acheté Electricité mobile, votre SPS sera activé prochainement'

i want to remove this backslash
i tried like this but get exception

ddd=xx.decode('string_escape')

EncodeError: 'ascii' codec can't encode character u'xe9' in position 19: ordinal not in range(128)

any help will be appriciated

Asked By: ohadshay

||

Answers:

How about trying ‘unicode_escape’

Answered By: Aswini

If it’s unicode, you should decode it this way:

xx.decode('UTF-8')

But str.decode() defaults to 'UTF-8' so you actually could leave out the argument

Answered By: Sim Son
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.