I have a string in python2.7 like this,
This is some u03c0 text that has to be cleanedu2026! itu0027s annoying!
How do i convert it to this,
This is some text that has to be cleaned! its annoying!
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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 cleanedu2026! itu0027s annoying!'
>>> s.encode('ascii', 'ignore')
b"This is some text that has to be cleaned! it's annoying!"
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0