I have a string in python2.7 like this,
This is some \u03c0 text that has to be cleaned\u2026! it\u0027s annoying!
How do i convert it to this,
This is some text that has to be cleaned! its annoying!
In python, to remove Unicode ” u “ character from string then, we can use the replace() method to remove the Unicode ” u ” from the string. After writing the above code (python remove Unicode ” u ” from a string), Ones you will print “ string_unicode ” then the output will appear as a “ Python is easy. ”.
Remove Non-ASCII Characters From Text Python Here we can use the replace() method for removing the non-ASCII characters from the string. In Python the str. replace() is an inbuilt function and this method will help the user to replace old characters with a new or empty string.
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!"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With