python3 encode replace unicode characters

Viewed 3573

According to the documentation, the following command

'Brückenspinne'.encode("utf-8",errors='replace')

Should give me the byte sequenceb'Br??ckenspinne'. However, unicode characters are not replaced but encoded nevertheless :

b'Br\xc3\xbcckenspinne'

Can you tell me how I actually eliminate unicode characters ? (I use replace for testing purposes, I intend to use 'xmlcharrefreplace' later. To be totally honest, I want to convert the unicode characters to their xmlcharref, keeping everything as a string).

Thank you.

1 Answers
Related