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
Answers:
How about trying ‘unicode_escape’
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
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
How about trying ‘unicode_escape’
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