Is that the correct path to the file, without any typos?

os.path.abspath and os.path.join don't do any checking on whether their 
resulting path exists. So if there is a typo or error in your path it doesn't 
get reported until you actually try and open it by running ElementTree.parse

You can check if your path is ok using either os.path.exists() or 
os.path.isfile() before trying to actually open it to see if it is already 
there.



-----Original Message-----
From: Python-list <python-list-bounces+david.raymond=tomtom....@python.org> On 
Behalf Of Dipangi Shah
Sent: Tuesday, July 30, 2019 3:20 AM
To: python-list@python.org
Subject: Xml File Error

Hi,

import os from xml.etree import ElementTree
file_name = 'Users.xml' full_file = os.path.abspath(os.path.join('data',
file_name)) print(full_file) with above code, path is successfully printed
as "C:\Users\Evosys\PycharmProjects\Python Level1\data\Users.xml" but when
I add below 2 lines, there is an error saying "FileNotFoundError: [Errno 2]
No such file or directory: 'C:\\Users\\Evosys\\PycharmProjects\\Python
Level1\\data\\Users.xml' dom = ElementTree.parse(full_file,None) print(dom) Can
you suggest to me why I am facing the error?

-- 
Regards,

Dipangi Shah
-- 
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to