Python Forum
io.UnsupportedOperation: not readable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
io.UnsupportedOperation: not readable
#1
I've already imported csv, so I don't understand why it's complaining about line 20 in the following code:

#!/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, "w", 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()
Error:
Traceback (most recent call last): File "I:\Python\Python36-32\SamsPrograms\MovieListCSV.py", line 72, in <module> main() File "I:\Python\Python36-32\SamsPrograms\MovieListCSV.py", line 56, in main movies = readMovies() File "I:\Python\Python36-32\SamsPrograms\MovieListCSV.py", line 20, in readMovies for row in reader: io.UnsupportedOperation: not readable >>>
Reply


Messages In This Thread
io.UnsupportedOperation: not readable - by RedSkeleton007 - Apr-05-2018, 12:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  io.UnsupportedOperation: fileno toml12953 3 1,730 Jun-15-2023, 08:48 PM
Last Post: toml12953
  How to make x-axis readable with matplotlib Mark17 7 3,933 Mar-01-2022, 04:30 PM
Last Post: DPaul
  Function global not readable by 'main' fmr300 1 1,352 Jan-16-2022, 01:18 AM
Last Post: deanhystad
  io.UnsupportedOperation: not readable navidmo 1 3,528 Oct-31-2019, 11:04 PM
Last Post: ichabod801
  Display output in readable format and save hnkrish 1 2,636 Jul-19-2019, 09:29 AM
Last Post: Larz60+
  How to convert Python crawled Bing web page content to human readable? dalaludidu 4 3,419 Sep-02-2018, 04:15 PM
Last Post: dalaludidu
  Time Difference in Epoch Microseconds then convert to human readable firesh 4 11,644 Feb-27-2018, 09:08 AM
Last Post: firesh
  which code is more readable? Skaperen 5 5,718 Nov-14-2016, 02:37 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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