Skip to content Skip to sidebar Skip to footer

Python Xml.etree.elementtree Directory Acess

import xml.etree.ElementTree as ET ID='000296166' tree = ET.parse('\folder' + ID +'.xml') root = tree.getroot() What I'm trying to do is access XML files that aren't in the same

Solution 1:

\f is interpreted as the page brake and is replaced with hex code 0xC. You should remove leading backslash from path.

tree = ET.parse("folder" + ID +'.xml')

And if you use backslash inside strings it can be escaped like this \\

EDIT

When you work with paths it is better to use os.path module:

 import os 
 ...
 tree = ET.parse(os.path.join('folder', ID + '.xml'))

Post a Comment for "Python Xml.etree.elementtree Directory Acess"