Post
Python
Why Python open() is giving an error called IOError: Errno 2 no such file or directory?
I am trying to open a file like this
My_file = open(‘updated.yaml’)
Posted on 23rd April 2024
The file might be there but may have a different path so try writing the correct and complete path for the file
Try this
My_file = open(r'Drive:\Dir\Updated.yaml')
Posted on 23rd April 2024
Most likely, the problem is that you're using a relative file path to open the file.
An absolute path is a path that starts with your computer's root directory, for example 'C:\Python\scripts..' if you're on Windows.
A relative path is a python path that does not start with your computer's root directory, and is instead relative to something called the working directory. You can view Python's current working directory by calling os.getcwd().
Use an absolute path to open the file:
file = open(r'C:\path\to\your\file.ext')
STILL GOT QUERIES?