0

ValueError: too many values to unpack ( expected 2)

This is error it shows everytime I run from sys import argv script, input_file = argv

19th May 2020, 2:13 PM
Sandeep Barnwal
Sandeep Barnwal - avatar
3 Respostas
+ 1
from sys import argv script, input_file = argv def print_all(f): print(f.read()) def rewind(f): f.seek(0) def print_a_line(line_count, f): print(line_count, f.readline()) current_file = open(input_file) print("First let's print the whole file:\n") print_all(current_file) print("Now let's rewind, kind of like a tape.") rewind(current_file) print("Let's print three lines:") current_line = 1 print_a_line(current_line, current_file) current_line = current_line + 1 print_a_line(current_line, current_file) current_line = current_line + 1 print_a_line(current_line, current_file)
19th May 2020, 2:31 PM
Sandeep Barnwal
Sandeep Barnwal - avatar
+ 4
Please share your complete code here. To get a clear picture of what happens, a short snippet is not very helpful. Thanks!
19th May 2020, 2:20 PM
Lothar
Lothar - avatar
+ 4
The code you showed here, is meant to be started from the os command line e.g.: python test1file.txt To get the code run i have slightly modified the first few lines. What you have to do is to create a txt file with at least 4 lines. The name of this file has to be used in the code, and the file should be in the same directory: https://code.sololearn.com/cRKwo4DbUkL7/?ref=app
19th May 2020, 5:28 PM
Lothar
Lothar - avatar