You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中CSV读取器持续报FileNotFoundError求助

Fixing the FileNotFoundError for Your CSV File

Hey there! Let's work through this file path issue together—it's super common when you're starting out with file handling in Python, so you're not alone here.

First, Let's Spot the Mismatch

Looking at your error message:

FileNotFoundError: [Errno 2] No such file or directory: '..\Downloads\netflix_ratings.csv.csv'

But your code uses this path:

csvpath = os.path.join("C:", "Desktop", "Python2", "netflix_ratings.csv.csv")

The problem is clear: your code is looking for the file on your Desktop, but the error shows the file is actually in your Downloads folder. That's why Python can't find it!

Step-by-Step Fixes

  • Get the correct file path
    Locate your netflix_ratings.csv.csv file in File Explorer. Right-click it, select "Properties", then copy the "Location" (e.g., C:\Users\YourName\Downloads). Use that location to build your path in code:

    csvpath = os.path.join("C:", "Users", "YourName", "Downloads", "netflix_ratings.csv.csv")
    

    Replace YourName with your actual Windows username.

  • Verify the path before opening the file
    Add a print statement to check if your path is correct—this helps catch typos early:

    print("Checking file path:", csvpath)
    

    Copy the printed path into File Explorer's address bar; if it opens your file, you know the path is right.

  • Fix the double .csv suffix (optional but clean)
    That .csv.csv suffix probably happened because Windows hides file extensions by default. To fix this:

    1. Open File Explorer, go to "View" > check "File name extensions".
    2. Rename the file to netflix_ratings.csv and update your code to match the new filename.

Modified Working Code

Here's your code with the fixes applied (don't forget to replace the path with your actual one):

import os
import csv

video = input("What show or movie are you looking for? ")
# Replace with your actual file path
csvpath = os.path.join("C:", "Users", "YourName", "Downloads", "netflix_ratings.csv.csv")
print("Checking file path:", csvpath)

found = False
try:
    with open(csvpath, newline="") as csvfile:
        csvreader = csv.reader(csvfile, delimiter=",")
        # Uncomment the line below if your CSV has a header row
        # next(csvreader)
        for row in csvreader:
            if row[0] == video:
                print(f"{row[0]} is rated {row[1]} with a rating of {row[5]}")
                found = True
except FileNotFoundError:
    print(f"Oops! Couldn't find the file at {csvpath}. Double-check the path and filename.")

if not found:
    print("Sorry about this, we don't seem to have what you are looking for!")

内容的提问来源于stack exchange,提问作者Dessamol

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:09:47