0

I have the following line of code: xml = BytesIO("<A><B>some text</B></A>") for the file named test.xml.

But I would like to have something like xml = "/home/user1/test.xml"

How can I use the file location instread of having to put the file content?

3 Answers 3

1

Exactly like you have. lxml.etree.parse() accepts a string filename and will read the file for you.

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

Comments

0

The following code will read in the contents of the file into a string, and pass it into the class instantiator for BytesIO

xml = BytesIO(open("/home/user1/test.xml").read())

Comments

0
xml = open('/home/user1/test.xml', 'rb').read()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.