""" Reading files in Python """ # in order to read from a file you first need to open it: file_handle = open('numbers.txt') # you can obtain the next line in the file using its readline method line = file_handle.readline() file_handle = open('numbers.txt') for line in file_handle : print line # once we're done with a file we close it: file_handle.close() # It is a good idea to check whether a file exists before attempting # to open it: import os os.path.exists('numbers.txt') # now let's extract the numbers in the file into a list: numbers = [] file_handle = open('numbers.txt') for line in file_handle : numbers += [int(line)]