hey, i need a way to grab a reasonably random line from a text file in
python.
I'm using a really lame 'read all the lines in and select one at random'
system right now, but i'd like something more efficient since the text
file will grow quite a bit.
I came accross somebody else's suggestion of:
text = None
for line in fileinput.input():
if random.randrange(fileinput.lineno()) ==0:
text = line
But couldn't that complete without selecting a line?
-Lkb
--
If there's anything more important than my ego around, I want it caught
and shot now.
-- Zaphod Beeblebrox
_______________________________________________
Bits mailing list
[EMAIL PROTECTED]
http://www.sugoi.org/mailman/listinfo/bits