Re: reading from a text file

2009-11-30 Thread Tim Golden
inhahe wrote: i don't understand the point of using 'with' but i don't understand what 'with' does at all i've tried to understand it a few times anyway here: import random result = random.choice(open("c:\\test.txt").readlines()) Yep. That'll do the trick. The point of "with" is that, while i

Re: reading from a text file

2009-11-30 Thread inhahe
i don't understand the point of using 'with' but i don't understand what 'with' does at all i've tried to understand it a few times anyway here: import random result = random.choice(open("c:\\test.txt").readlines()) On Mon, Nov 30, 2009 at 10:41 AM, Tim Golden wrote: > Olof Bjarnason wrote: >> >

Re: reading from a text file

2009-11-30 Thread Tim Golden
Olof Bjarnason wrote: 2009/11/27 baboucarr sanneh : hi all i would like to create a python program that would read from a text file and returns one result at random. e.g in the text file i have these data 1.hello 2.my name 3.is 4.World Your help is highly appreciated..thnx in advance Hi bab

Re: reading from a text file

2009-11-30 Thread Esmail
baboucarr sanneh wrote: i would like to create a python program that would read from a text file and returns one result at random. #!/usr/bin/env python # assuming the file fits into memory, and you are interested in # random lines from random import randrange f = open('data.txt') data =

Re: reading from a text file

2009-11-30 Thread Simon Brunning
2009/11/27 baboucarr sanneh : > hi all > > i would like to create a python program that would read from a text file and > returns one result at random. This might be of use: http://code.activestate.com/recipes/426332/#c2 -- Cheers, Simon B. -- http://mail.python.org/mailman/listinfo/python-lis

Re: reading from a text file

2009-11-30 Thread Olof Bjarnason
2009/11/27 baboucarr sanneh : > hi all > > i would like to create a python program that would read from a text file and > returns one result at random. > e.g > in the text file i have these data > > 1.hello > 2.my name > 3.is > 4.World > > Your help is highly appreciated..thnx in advance Hi babour

reading from a text file

2009-11-30 Thread baboucarr sanneh
hi all i would like to create a python program that would read from a text file and returns one result at random. e.g in the text file i have these data 1.hello 2.my name 3.is 4.World Your help is highly appreciated..thnx in advance $LIM $...@dy ___