Python Forum
FileNotFoundError: [Errno 2] No such file or directory: 'movies.csv'
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FileNotFoundError: [Errno 2] No such file or directory: 'movies.csv'
#1
I tried to run my movie list program:

#!/usr/bin/env python3
#MovieListCSV.py
#This program does pretty much the same thing as MovieList2D.py. The only
#difference about this program is that it calls the writeMovies function
#whenever the user updates the list, so that the data is still saved if this
#program crashes.
import csv

FILENAME = "movies.csv"

def writeMovies(movies):
    with open(FILENAME, "w", newline="") as file:
        writer = csv.writer(file)
        writer.writerows(movies)

def readMovies():
    movies = []
    with open(FILENAME, "r", newline="") as file:
        reader = csv.reader(file)
        for row in reader:
            movies.append(row)
        return movies

def listMovies(movies):
    for i in range(len(movies)):
        movie = movies[i]
        print(str(i+1) + ". " + movie[0] + " (" + movie[1] + ")")
    print()

def addMovie(movies):
    name = input("Name: ")
    year = input("Year: ")
    movie = []
    movie.append(name)
    movie.append(year)
    movies.append(movie)
    writeMovies(movies)
    print(name + " was added.\n")

def deleteMovie(movies):
    index = int(input("Movie Number: "))
    movie = movies.pop(index - 1)
    writeMovies(movies)
    print(movie[0] + " was deleted.\n")

def displayMenu():
    print("COMMAND MENU")
    print("list - List all movies")
    print("add  - Add a movie")
    print("del  - Delete a movie")
    print("exit - Exit the program")
    print()

def main():
    displayMenu()
    movies = readMovies()
    while True:
        command = input("Enter Command: ")
        if command.lower() == "list":
            listMovies(movies)
        elif command.lower() == "add":
            addMovie(movies)
        elif command.lower() == "del":
            deleteMovie(movies)
        elif command.lower() == "exit":
            break
        else:
            print("Invalid command. Please try again.")
    print("Bye!")

if __name__ == "__main__":
    main()
But apparently, storing the movies.csv file into the FILENAME global constant didn't work:

Error:
>>> ================================ RESTART ================================ >>> COMMAND MENU list - List all movies add - Add a movie del - Delete a movie exit - Exit the program Traceback (most recent call last): File "F:\Python\Python36-32\SamsPrograms\MovieListCSV.py", line 72, in <module> main() File "F:\Python\Python36-32\SamsPrograms\MovieListCSV.py", line 56, in main movies = readMovies() File "F:\Python\Python36-32\SamsPrograms\MovieListCSV.py", line 18, in readMovies with open(FILENAME, "r", newline="") as file: FileNotFoundError: [Errno 2] No such file or directory: 'movies.csv' >>>
What's wrong? Why isn't movies.csv being created?
Reply


Messages In This Thread
FileNotFoundError: [Errno 2] No such file or directory: 'movies.csv' - by RedSkeleton007 - Jul-01-2018, 06:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error (Errno 2), File upload with the Flask framework and a public IP Username_Python1 0 366 Mar-28-2024, 01:46 PM
Last Post: Username_Python1
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,692 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,760 Jun-27-2023, 01:17 PM
Last Post: diver999
  Extract file only (without a directory it is in) from ZIPIP tester_V 1 1,096 Jan-23-2023, 04:56 AM
Last Post: deanhystad
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,194 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  no such file or directory in SFTP saisankalpj 2 1,663 Nov-25-2022, 11:07 AM
Last Post: DeaD_EyE
Photo Making Zip file of a file and Directory Nasir 2 1,088 Oct-07-2022, 02:01 PM
Last Post: Nasir
  Failed to execute child process (No such file or directory) uriel 1 1,712 Sep-15-2022, 03:48 PM
Last Post: Gribouillis
  Need Help: FileNotFoundError:[Errno 2] No such file or directory python202209 5 2,808 Sep-12-2022, 04:50 AM
Last Post: python202209
  importing functions from a separate python file in a separate directory Scordomaniac 3 1,455 May-17-2022, 07:49 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020