#!/usr/bin/env python # assuming the file fits into memory, and you are interested in # random lines from random import randrange f = open('data.txt') data = f.readlines() f.close() # done with file number = len(data) pick = randrange(0, number) print data[pick] raw_input('\n to exit.')