On 15/07/07, max baseman <[EMAIL PROTECTED]> wrote: > im writing a quick quote reader that spits out a random quote from a > show but cant get it to pick randomly > i tried > a=randrange(820)+1 > text.readline(a) > > and i would prefer not having to bring evryline into the program then > picking like
The 'fortune' program in unix/linux produces random quotes from a quote file. As I understand it, it builds separate index files for each input file. I'm not sure exactly how it works, but I would guess the index files contain byte offsets for the start and end of each quote. So you would read the whole index file (which will be much shorter than the main quote file), select one at random, then use .seek() and .read() to read just the bytes you are interested in from the main file. -- John. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor