logo-MindMajix
PostPythonPython
christina joce

Posted on 13th June 2024|32 views

0
votes

Ioerror Errno 2 No Such File Or Directory:

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’)

 

2 answers
Answers
P
Sowjanya Kodiganti

Posted on 13th June 2024| views

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')

 

P
elonvengas

Posted on 13th June 2024| views

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')

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo

  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos
Name
Course *
Email *
Phone Number