sumanth shetty
sumanth shetty

Reputation: 2181

Error while reading CSV file No such file or directory

I am trying to read a CSV file which is present in the same folder as my python script.

I am not able to figure out why csv is not been able to pick up the rile.

here is the below code i am using.

with open(r"C:\Users\*****\Desktop\Book1.csv", encoding = 'utf-8') as file:
    csv_data = csv.reader(file)
    print (csv_data)

Here is the error:

with open(r"C:\Users\******Desktop\Book1.csv", encoding = 'utf-8') as file:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\*****\\Desktop\\Book1.csv'

Also i tried with the relative path but still the same error.

I am using the latest version of python 3.10

any idea on how can i pass over this?

Upvotes: 0

Views: 678

Answers (1)

Amey
Amey

Reputation: 480

  1. check files like this probably you are missing some _,-,.
  2. try removing the raw tag from the file dir
import os

cwd = os.getcwd()  # Get the current working directory (cwd)
files = os.listdir(cwd)  # Get all the files in that directory
print(f"Files in {cwd}: {files}") 

Upvotes: 2

Related Questions