I have been trying to get ElementTree(ET) to look for xml files in a specific directory which the user will point to, however I found out that ET is only searching for that xml file in the directory of the script itself. How can I force ET to look in the right directory, and why is it ignoring the one that is passed down to it?
The code is split into two different scripts.
main.py:
#This script is mainly a tkinter script with buttons/entries. One button takes the given directory and passes it over to a function that launches the second script/function. Including this here to better make sense of how the code will be working
.
.
def clicked(self):
check_xml(self.directory)#the value that is stored from a different button
classes.py:
import os
import glob
import xml.etree.ElementTree as ET
def check_xml(x):
tree = ET.parse('sample.xml')
root = tree.getroot()
print(tree)
The folder structure is as follows: root/main folder(This is what 'self.directory' and 'x' will point to):
|--projectFolder
|--subfolder
|--anotherXML.xml
|--sample.xml
Eventually I would go into the other xml's but right now I'm trying to work my way up(down?) by making sure the code works correctly and displays the information I want.
Why is it that 'x' gets ignored by the function, and instead only checks the directory that the code itself is in only, and how can I get it to work correctly?