# Fileprint.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-05-14 File created. # 2022-12-18 Converted to Python 3. # This program does not check whether the file opening is # successful. The program can, however, inform the user if # the specified file does not exist. # The readline() method includes a newline character '\n' # at the end of the string that is read. An empty line thus # contains a single newline character. An empty string then # indicates the end of the file being read. print( "\n This program prints the contents of a text" \ "\n file to the screen. Give a file name: ", end="" ) file_name_from_user = input() file_to_print = open( file_name_from_user, 'r' ) line_counter = 0 end_of_file_encountered = False while end_of_file_encountered == False : text_line_from_file = file_to_print.readline() if text_line_from_file == "" : end_of_file_encountered = True else : print( text_line_from_file, end="" ) line_counter += 1 file_to_print.close() print( "\n %d lines printed." % line_counter )