Jul-21-2023, 03:53 PM
(This post was last modified: Jul-21-2023, 04:14 PM by deanhystad.)
Hi there! New to this forum and Python (Technically my first language I am learning to program in! :D) and I'm running into an issue that I don't quite understand.
So I've been watching youtuber video called Harvard CS50’s Introduction to Programming with Python – Full University Course on the channel freecodeCamp.org. During lecture at 8:09:01 we re-code what the previous example that he was explaining to make it easier to catch multiple columns in a CSV doc if it so happens to have any or some other format type. In the example we are using few Harry Potter Characters. Harry, Ron and Draco. End goal of this example is to pull data from a CSV doc that written like the following
Harry, "Number Four, Privent Drive"
Ron, The Burrow
Draco, Malfoy Manor
And to solve this what he suggest was us to import the library csv and use csv.reader to help us out with this to get the desire end result for the program to print: Harry is from Number Four, Privent Drive
Ron is from The Burrow
Draco is from Malfoy Manor.
And code we have written in Python
When lecturer in the video runs this line of code he gets the result we are looking for, But when I run it I get following Error Message:
Any ideas?
The link to the video I am watching is
https://www.youtube.com/watch?v=nLRL_NcnK-4&t=29112s
Time Stamps:
Example starts at 8:00:05
Running the code I wrote above is at 8:04:30
So I've been watching youtuber video called Harvard CS50’s Introduction to Programming with Python – Full University Course on the channel freecodeCamp.org. During lecture at 8:09:01 we re-code what the previous example that he was explaining to make it easier to catch multiple columns in a CSV doc if it so happens to have any or some other format type. In the example we are using few Harry Potter Characters. Harry, Ron and Draco. End goal of this example is to pull data from a CSV doc that written like the following
Harry, "Number Four, Privent Drive"
Ron, The Burrow
Draco, Malfoy Manor
And to solve this what he suggest was us to import the library csv and use csv.reader to help us out with this to get the desire end result for the program to print: Harry is from Number Four, Privent Drive
Ron is from The Burrow
Draco is from Malfoy Manor.
And code we have written in Python
1 2 3 4 5 6 7 8 9 10 11 |
import csv students = [] with open ( "harrypotter.csv" ) as file : reader = csv.reader( file ) for name, home in reader: students.append({ "name" : name, "home" : home}) for student in sorted (students, key = lambda student: student[ "name" ]): print ( f "{student['name']} is from {student['home']}" ) |
Error:line 7, in <module>
for name, home in reader:
^^^^^^^^^^
ValueError: too many values to unpack (expected 2)
And I am not sure why. I've looked and read the code multiple times, I've looked at what the lecturer wrote and compared and I just don't understand Why mines is failing and yet when he ran his it passed and worked.Any ideas?
The link to the video I am watching is
https://www.youtube.com/watch?v=nLRL_NcnK-4&t=29112s
Time Stamps:
Example starts at 8:00:05
Running the code I wrote above is at 8:04:30
deanhystad write Jul-21-2023, 04:14 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.