paljenczy
paljenczy

Reputation: 4899

Python 3 - utf-8 str to latin character

I have a string in Python 3.5:

In [2]: foo
Out[2]: 'Attila_Szedl%C3%A1k'

I would like to turn it to something like

In [3]: foo_mod
Out[3]: 'Attila_Szedlák'

That is, I want to turn the "á" character's utf-8 code to something that is actually an "á". What is the mapping from foo to foo_mod?

I have tried

In [4]: foo_mod = foo.encode("latin-1")

In [5]: foo_mod
Out[5]: b'Attila_Szedl%C3%A1k'

But this is apparently not what I want.

Upvotes: 1

Views: 132

Answers (1)

wim
wim

Reputation: 362707

That string looks url encoded. The tool you want is in urllib

>>> s
'Attila_Szedl%C3%A1k'
>>> urllib.parse.unquote(s)
'Attila_Szedlák'

Upvotes: 3

Related Questions