0

I write some string on another language and save it to xml file, but the strings looks like

# A part of the xml: recipientname="Калик Мамадо.."  

tree.write(new_file_name)  # Tree is a xml (ElementTree.parse(file))

with open(new_file_name, 'r') as xml_document:
     xml = xml_document.read().replace('\n', '')

How i can decode it to normal string?

2 Answers 2

1

These are no bytes, its HyperText Markup Language https://docs.python.org/3/library/html.html

You can use:

import html
x = html.unescape("ад")
print(x) # This gives ---> ад

Edit, you can just pass the whole file in the function.

Sign up to request clarification or add additional context in comments.

Comments

0

That's to be excepted. These characters are encoded, they will be displayed and read in correctly. While you can use Cyrillic directly in your text, it will be rendered as unicode entities when written to file.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.