Question about exercise 26 LPTHW3

I am working on exercise 26 (the test) and have figured it all out except:

from sys import argv
script, filename = argv

txt = open(filename)

print("Type the filename again:")
file_again = input("> ")

txt_again = open(file_again)


Its asking for another argument which I believe is the file but which file?

Any hints?

Thank you.

Leroy Fass

You have




The answer @scla is right, but two things to remember:

  1. Any time you get an error, google for the error, and go quadruple check the line that it mentions, then each line above that until you find the mistake.

  2. Sometimes comparing a line backwards and reading out each character helps you find it. You would have seen the missing . if you did that. This doesn’t scale for real code later, but it does train your brain to really read code slowly and see errors.

I also indented your code 4 spaces so it’d format right on the forum.

1 Like

Please note - the copy/paste text from the exercise 26 has txt_again_read not

My problem however is this:
LEROYs-iMac:lpthw leroyfass$ python3
How old are you? 77
How tall are you? 57
How much do you weigh? 144
So, you’re 77 old, 57 tall and 144 heavy.
Traceback (most recent call last):
File “”, line 10, in
script, filename = argv
ValueError: not enough values to unpack (expected 2, got 1)

Its asking for another argument which I believe is the file but which file?

You pass the filename of the file you want to read. I used a file called “junk.txt” that had some junk in it.

Hope that helps

Alright, well you should know what that means at this point. You’re using argv, and you didn’t run your script with a command line argument.

I’m going to suggest something bizarre but try it out. I think you may be running to get help before you’ve tried to solve it yourself. The above question definitely looks like that. What you should do is, before you ask for help, email yourself a description of the problem you’re having then go take a break for a little while. Specifically ask yourself, what might be causing it, and list what you’ve tried already. You’d be surprised how well this works in finding the answer.

1 Like

yea, I knew the .read() was not addressing the command line issue, but…, even with the command line solved it wasn’t going to run anyway… :slight_smile:

@scla is right that you need to change it to .read() but that has nothing to do with your question (argv).

When you are calling exercise 26, you are calling the script, you can see though that there are two variables for argv, one being a file name, are you calling a file name too? If not, it expected two variables ( script name and file name).

Hope that helps.