--- [EMAIL PROTECTED] wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, > visit > http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body > 'help' to > [EMAIL PROTECTED] > > You can reach the person managing the list at > [EMAIL PROTECTED] > > When replying, please edit your Subject line so it > is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. Re: Print record x in a file (Kent Johnson) > 2. How would python messure up in performance? > (Kevin) > 3. Re: How would python messure up in > performance? (Max Noel) > 4. Re: Print record x in a file (David Holland) > 5. on the way to find pi (Ali Polatel) > 6. Re: on the way to find pi (Max Noel) > 7. Re: on the way to find pi (Orri Ganel) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Sun, 23 Jan 2005 07:46:08 -0500 > From: Kent Johnson <[EMAIL PROTECTED]> > Subject: Re: [Tutor] Print record x in a file > Cc: tutor python <tutor@python.org> > Message-ID: <[EMAIL PROTECTED]> > Content-Type: text/plain; charset=ISO-8859-1; > format=flowed > > Since len(listcontents) is one greater than the > largest valid index of listcontents, the correct > use of randrange() for this problem is > x = random.randrange(0, len(listcontents)) >
Kent, I know that you know far more about python than me but is that right ? I created file with 4 records and this code did print them all randomly:- import random i = 0 while i < 10: file = open('filename') listcontents = file.readlines() file.close() lenoflist = len(listcontents)-1 x = random.randrange(0,lenoflist) print listcontents[x], i i = i +1 While although this code below does work many times nothing is printed out. import random i = 0 while i < 10: file = open('test.rantxt') listcontents = file.readlines() file.close() lenoflist = len(listcontents)#-1 x = random.randrange(0,lenoflist) print listcontents[x], i i = i +1 ___________________________________________________________ ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor