-1

I'm trying to create a list of named tuples from a CSV file. The error pulls up on line 12(the one starting with movie_list). It says that there are not enough values to unpack. I've done multiple other projects using this exact method, and no errors ever. Please, do not suggest alternate methods, as this is for a school project and has to be done this way.

Movie = namedtuple("Movie", "index, title, release, user_rating, metascore, imdb_votes, plot, genre, runtime, revenue, actors, director")

    def read_data (file, encoding='utf-8'):
        with open(file):
            reader = csv.reader(file)
            next(reader)
            movie_list =[Movie(int(index), title, int(release), float(user_rating), float(metascore), int(imdb_votes), plot, genre, int(runtime), float(revenue), actors, director)
                        for index, title, release, user_rating, metascore, imdb_votes, plot, genre, runtime, revenue, actors, director in reader]
            
        return movie_list
Venkata Shivaram
  • 343
  • 4
  • 18

1 Answers1

0

If file is the string like path to the file then reader is reading this string 1 character at a time not the actual file.

with open(file, 'r') as fh:
    reader = csv.read(fh)
MYousefi
  • 978
  • 1
  • 5
  • 10
  • It would be worth mentioning that OP created an anonymous file object in `with open(file):` - it didn't change the `file` variable from the file name to the file object. – tdelaney Dec 24 '20 at 16:43
  • Thank you! This was the error. Everything's working now. I don't know how I could've missed that ^^" – victoriaemc Dec 24 '20 at 16:56