EX 20: having error when running codes on exercise 20


I get this following error:

“ValueError: not enough values to unpack (expected 2, got 1)”

while i was trying to run below codes


can anyone please help on it?


I suspect you forgot to pass a filename when you ran it so sys.argv didn’t have enough values.


i have used this highlighted file residing on the same directory,

yet the same error is coming :frowning:

Hello @littleman.

What @florian mean is that you have to provide the text file along the Python file.

In this lesson Python read from a text file.
Your traceback shows that it haven’t got it.

Yes. If we’re correct then this is all about the prompt that you write to start the script. My suspicion is that you did

python ex20.py

when you should have done

python ex20.py inputfile.txt

— Python needs to know which file it should use.

thank you very much @florian and @ulfen69; i did realize it while i went back to exercise 13.


now here comes another problem

when i use def print_a_line(line_count, f):
print(line_count, f.readline())


print (" first lets print the whole file")




print(current_line, current_file)

i got following o/p


but if i use print(current_line, current_file.readline()) i get exactly what it meant for in the forth line of the o/p:


what’s wrong if i dont put .readline() inside the function? (not in defining function but in using function!)

interesting o/p, difference between line 4 and line 5

Hey @littleman, so first up, you can post a copy-paste of your powershell window by putting it here like this:

# powershell output or other code here

Or like this:

# code or powershell output here

Next, I think you’re just getting in over your head and should probably just continue on with the book, but pay more attention. What’s happening is you’re running into a little problem, running to the forum for help, but you have to stop and try to solve it yourself first. When you run into a problem in programming, you have to spend at least 1 day researching why you caused it, then go get help.

One tip is to email your question to yourself first. That actually helps you figure it out.

1 Like