# # file: read-from-file_lists.py # This program opens a file "numbers.dat", reads all the information from it # and displays it on the screen. # !!! Please, note the the input file "numbers.dat" should be stored in the # same place your program is. # # The program uses readlines() function def main(): in_stream=open("numbers.dat","r") list_of_strings=in_stream.readlines() # list_of_strings is a list of strings, # each element of that list refers to corresponding string in the file "numbers.dat" n=len(list_of_strings) # how many elements in the list 'list_of_strings' print "The contents of the file %s is:" % ("numbers.dat") # printing out all elements of the list 'list_of_strings' one by one. # we keep in mind that all the strings except the last one have # newline character at the end, and we don't want to display it for i in range(n): if i!=n-1: print list_of_strings[0][:-1] # makes sure that the newline # character is not displayed on the screen else: print list_of_strings[1] print "And this is how the list of strings is looks like:" print list_of_strings main()