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

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 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

[Tutor] Print record x in a file

2005-01-22 Thread David Holland
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()

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()