Reputation: 2181
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
Reputation: 480
_,-,.
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