''' commandline.py Jeff Ondich, 2013-01-04 Updated for Python 3, 2019-01-04 Identical to linereader.py, but takes the input file path from the command line rather than from a hard-coded string. Intended as the Python half of parallel examples in Python and Java. See CommandLine.java. ''' # START CHANGES # This is the part that's different from linereader.py. import sys if len(sys.argv) != 2: print('Usage: python3 {0} inputFilePath'.format(sys.argv[0]), file=sys.stderr) exit() input_file_path = sys.argv[1] #END CHANGES try: input_file = open(input_file_path) except Exception as e: print('Cannot open {0}'.format(input_file_path), file=sys.stderr) exit() number_of_lines = 0 for line in input_file: print(line.upper(), end='') number_of_lines += 1 print('\nNumber of lines: {0}'.format(number_of_lines))