[Tutor] read a random line from a file
Mon, 17 Dec 2001 01:25:23 -0500
On Sun, Dec 16, 2001 at 11:20:29PM -0500, Kirk Bailey wrote:
> OK, I know there is a simple way to do it, and I cannot locate the
> correct ommand. I want to open a flat text file, read ONE randomly
> selected line into a string, and close the file. I need the command for
> reading a line at random, and what module it is in. I understand there
> is such a command already defined, and it is simple to use, but canot
> find it again.
import os, sys, random
proj = os.path.expanduser("~/.t/p")
f = open(proj)
projects = 
lines = f.readlines()
for l in lines:
It's good if file isn't too large..
> -Kirk D Bailey (C)2001
> Addme! icq #27840081
> Within the sweep of his sword, Each man is an Ubar.
> Tutor maillist - Tutor@python.org
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org