Hi @Redtreble, you need to take some more time to figure things out before coming to ask for help. In this example you seem to get an error, immediately stop, ask for help, then blindly type the help and repeat the process. To get better at programming you must spend time to figure out why something is broken and try to do things to fix it on your own before you ask for help. Otherwise you won’t learn anything or be able to work on your own or make anything on your own.
Let’s take this for example. You got the error “too many values to unpack”. When you get an error you google for it, so let’s see what you get when you google for “python too many values to unpack”:
https://www.google.com/search?client=firefox-b-1-d&q=python+too+many+values+to+unpack
I know people who code all day by just doing that. That should be your first step. Second step is to go back to the exercise and re-read it, carefully. In this example, I tell you how to run it, you’re just not seeing it. Go look. I run it differently from you and explain what’s going on.
The next thing to do is to try and figure out what the message means. “Too many values…” that means you are making too many variables. “To unpack…” if you read some of the things above in the google search you start to find out that what’s happening is called “unpacking”. Bascially, it’s this:
- The equal sign is assignment here, and it rules everything.
- The left of the equals sign you have a list: script, input_file
- The right of the equals sign you have a variable.
- There are two items in the list on the left.
- That means there is probably MORE THAN TWO things inside argv on the right.
- The “unpacking” means python is taking whatever is in argv, and unpacking it into each variable on the left, and your argv is too large.
Alright, so what’s going into argv?
python ex20.py first second
Try this:
print(argv)
Put that right above the line that’s causing the error. Any time you get an error with some variables, print them out and see what’s inside them. You’ll find out that argv has THREE contents in a list, but you only have TWO variables on the left. Thus, too many variables are in argv to unpack into your two on the left.
Now, read through all of that and spend some time to figure out what’s going on before you come back. This isn’t to rush you off and make you feel dumb, but more to help you get better at programming since programming is ALLLLLLLLLL about solving complex problems on your own.
Let us know when you get it.