Re: [Tutor] Print record x in a file

2005-01-23 Thread Kent Johnson
Max Noel wrote: On Jan 23, 2005, at 22:08, Liam Clarke wrote: Don't you mean x=random.randint(0, lenoflist) ?? I'm assuming you want an integer. random.randrange() returns an item (which can be a float or whatever, but by default is an int) in the specified range. In that case, an int betwee

Re: [Tutor] Print record x in a file

2005-01-23 Thread Max Noel
On Jan 23, 2005, at 22:08, Liam Clarke wrote: Don't you mean x=random.randint(0, lenoflist) ?? I'm assuming you want an integer. random.randrange() returns an item (which can be a float or whatever, but by default is an int) in the specified range. In that case, an int between 0 and lenoflist.

Re: [Tutor] Print record x in a file

2005-01-23 Thread Liam Clarke
gt; >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 2

Re: [Tutor] Print record x in a file

2005-01-23 Thread David Holland
--- "Jacob S." <[EMAIL PROTECTED]> wrote: > > This will get a random record > > I hope you do not think the comments are > patronising > > but you did say you are new so I did not want to > give > > naked code. > > > > import random > > #the above gives the program the ability to get a > > #pseud

Re: [Tutor] Print record x in a file

2005-01-23 Thread Kent Johnson
Jacob S. wrote: import random #the above gives the program the ability to get a #pseudo random number file = open('test.rantxt') listcontents = file.readlines() #gives you the file as a list of records or it did on #(assuming each line is a record) file.close() lenoflist = len(listcontents)-1 #find

Re: [Tutor] Print record x in a file

2005-01-22 Thread Orri Ganel
Jacob S. wrote: This will get a random record I hope you do not think the comments are patronising but you did say you are new so I did not want to give naked code. import random #the above gives the program the ability to get a #pseudo random number file = open('test.rantxt') listcontents = file.r

Re: [Tutor] Print record x in a file

2005-01-22 Thread Jacob S.
This will get a random record I hope you do not think the comments are patronising but you did say you are new so I did not want to give naked code. import random #the above gives the program the ability to get a #pseudo random number file = open('test.rantxt') listcontents = file.readlines() #give