0

I'm trying to create xml that corresponds to structure of directory (with subdirectories and files in that subdirs). When I try to use this example: Best way to generate xml? instead of output from example, that is:

<root> <child/> <child>some text</child> </root> 

I've got:

b'<root>\n <child/>\n <child>some text</child>\n</root>\n' 

Why is it so? Uses PyCharm IDE if it matters.

2 Answers 2

0

This is a change in Python 3. etree.tostring() is returning a bytes literal, which is denoted by b'string value'. Note that whenever you see \n in the bytes literal it means the same as a new line if you print it out to a file.

You can turn this into a regular string using s = s.decode('utf-8').

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

Comments

0

'\n' is a Line feed char (LF).

When you, for instance, save your output to a file and open it in some editor, you'll get what you expect.

Your output is fine.

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.