Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode encoding/decoding

I have a string that looks like this.

st = '/M\xe4rzen'

I would like to covert this to unicode. How can I do this? I've tried:

st.decode('utf-8')
unicode(t, 'utf-8')

The original file is utf-8 encoded, but I can't seem to get the unicode representation of the string.

like image 758
user1728853 Avatar asked Aug 01 '26 14:08

user1728853


1 Answers

Your data is not UTF8 encoded; more likely it is using the Latin-1 encoding:

>>> print st.decode('latin1')
/Märzen

Calling .decode() is enough, no need to also call unicode().

like image 186
Martijn Pieters Avatar answered Aug 03 '26 04:08

Martijn Pieters