See unicodedata.normalize
title = u"Klüft skräms inför på fédéral électoral große"
import unicodedata
unicodedata.normalize('NFKD', title).encode('ascii', 'ignore')
'Kluft skrams infor pa federal electoral groe'
Answer from Sorantis on Stack OverflowSee unicodedata.normalize
title = u"Klüft skräms inför på fédéral électoral große"
import unicodedata
unicodedata.normalize('NFKD', title).encode('ascii', 'ignore')
'Kluft skrams infor pa federal electoral groe'
You can use encode to ASCII if you don't need to translate the non-ASCII characters:
>>> a=u"aaaàçççñññ"
>>> type(a)
<type 'unicode'>
>>> a.encode('ascii','ignore')
'aaa'
>>> a.encode('ascii','replace')
'aaa???????'
>>>
Literal strings are unicode by default in Python3.
Assuming that text is a bytes object, just use text.decode('utf-8')
unicode of Python2 is equivalent to str in Python3, so you can also write:
str(text, 'utf-8')
if you prefer.
What's new in Python 3.0 says:
All text is Unicode; however encoded Unicode is represented as binary data
If you want to ensure you are outputting utf-8, here's an example from this page on unicode in 3.0:
b'\x80abc'.decode("utf-8", "strict")
python 3.x - Python3 - Convert unicode literals string to unicode string - Stack Overflow
Convert unicode to string in python - Stack Overflow
How to cast escaped unicode characters embeded into an string?
How to convert bytes to string in python?
Sorry for the weird question.
I got a string like this one:
Some text\r\n word word word\u0022
I think those backslashed characters are escape sequences, and i need to convert/cast them to the character they represent.
For example, i think the \u0022 is the doble quotes ( " ), so i need to convert the string to this:
Some text\r\n word word word"
Is it possible to do this whithout having to replace every character manually (with replace() string method)?
I don't know if i could convert the breakline. In that particular case, there wouldn't be a problem if i just replace it with a space, but i need to cast every other character.
I hope you could understand what i mean. Thanks in advance and sorry for this weird and tricky question.