我正在尝试读取CSV文件,该文件存在于与我的python脚本相同的文件夹中。
我不明白为什么csv不能捡起这个错误。
下面是我使用的代码。
with open(r"C:Users*****DesktopBook1.csv", encoding = 'utf-8') as file:
csv_data = csv.reader(file)
print (csv_data)
错误如下:
with open(r"C:Users******DesktopBook1.csv", encoding = 'utf-8') as file:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\*****\Desktop\Book1.csv'
我也尝试了相对路径,但仍然是相同的错误。
我正在使用最新版本的python 3.10
你知道我怎样才能跳过这个吗?
- 检查这样的文件,可能您缺少一些
_,-,.
- 尝试从文件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}")