Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a Unicode string to a string in Python (containing extra symbols)

How do you convert a Unicode string (containing extra characters like £ $, etc.) into a Python string?

like image 535
williamtroup Avatar asked Jul 30 '09 15:07

williamtroup


People also ask

How do you make a string containing Unicode characters in Python?

You have two options to create Unicode string in Python. Either use decode() , or create a new Unicode string with UTF-8 encoding by unicode(). The unicode() method is unicode(string[, encoding, errors]) , its arguments should be 8-bit strings.

How do you convert special characters in Python?

escape() method(for Python 3.4+), we can convert the ASCII string into HTML script by replacing ASCII characters with special characters by using html. escape() method. By this method we can decode the HTML entities into text. We can also use Beautiful Soup which handles entity conversion.

What does encoding =' UTF-8 do in Python?

UTF-8 is a byte oriented encoding. The encoding specifies that each character is represented by a specific sequence of one or more bytes.


1 Answers

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' 
like image 120
Sorantis Avatar answered Sep 21 '22 03:09

Sorantis