web-dev-qa-db-fra.com

Suppression d'unicode \ u2026 comme des caractères dans une chaîne en python2.7

J'ai une chaîne en python2.7 comme ça,

 This is some \u03c0 text that has to be cleaned\u2026! it\u0027s annoying!

Comment puis-je le convertir en cela,

This is some text that has to be cleaned! its annoying!
37

Python 2.x

>>> s
'This is some \\u03c0 text that has to be cleaned\\u2026! it\\u0027s annoying!'
>>> print(s.decode('unicode_escape').encode('ascii','ignore'))
This is some  text that has to be cleaned! it's annoying!

Python 3.x

>>> s = 'This is some \u03c0 text that has to be cleaned\u2026! it\u0027s annoying!'
>>> s.encode('ascii', 'ignore')
b"This is some  text that has to be cleaned! it's annoying!"
82
Burhan Khalid