4. Write a script called lineCounter that accepts a filename as a command line argument. It should run through the file line by line, displaying a character count for each line. The script should include a line counter, which records the line number, and is incremented when each line is processed.

Respuesta :

Answer:

from sys import argv

script, filename = argv

with open( filename ) as file:

      line_counter = 0

       while True:

               extract_line = file.readlines( )

               line_counter += 1

               character_count = extract_line.count( )

               print( " line number: { } , character count: { }". format( line_counter, character_counter )

         print ( " Nothing left to count" )

         file.close( )  

Explanation:

The 'argv' is a module in the python system package, which allows for user input and script execution in the command. It loads the script and the file as a tuple which is offloaded in the script like arguments in a function.