Re: Need help on reading line from file into list

2007-04-04 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Bruno Desthuilliers: >> result = [line.strip() for line in f.readlines()] > > Probably better, lazily: > result = [line.strip() for line in infile] This is of course better in the general case, but I wanted to stay consistant with the other examples... -- http://m

Re: Need help on reading line from file into list

2007-04-04 Thread bearophileHUGS
Bruno Desthuilliers: > result = [line.strip() for line in f.readlines()] Probably better, lazily: result = [line.strip() for line in infile] Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help on reading line from file into list

2007-04-04 Thread Duncan Booth
"bahoo" <[EMAIL PROTECTED]> wrote: > I don't see where the "str" came from, so perhaps the output of > "open('source.txt').readlines()" is defaulted to "str? Apart from Grant's explanation that str is the type of a string, what you perhaps haven't yet grasped is that if you have a type and an in

Re: Need help on reading line from file into list

2007-04-03 Thread Mel Wilson
bahoo wrote: [ ... ] > Thanks, this helped a lot. > I am now using the suggested > map(str.strip, open('source.txt').readlines()) > > However, I am a C programmer, and I have a bit difficulty > understanding the syntax. > I don't see where the "str" came from, so perhaps the output of > "open('sou

Re: Need help on reading line from file into list

2007-04-03 Thread Grant Edwards
On 2007-04-03, bahoo <[EMAIL PROTECTED]> wrote: > Thanks, this helped a lot. > I am now using the suggested > map(str.strip, open('source.txt').readlines()) > > However, I am a C programmer, and I have a bit difficulty > understanding the syntax. That bit of syntax is completely, utterly, 100%,

Re: Need help on reading line from file into list

2007-04-03 Thread Bruno Desthuilliers
bahoo a écrit : > On Apr 3, 5:06 pm, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote: > (snip) >> >>> open('source.txt').readlines() >>['0024\n'] >> >>> map(str.strip, open('source.txt').readlines()) >>['0024'] >> >>> open('source.txt').read() >>'0024\n' >> >>> list(open('source.txt').read().strip

Re: Need help on reading line from file into list

2007-04-03 Thread bahoo
On Apr 3, 5:06 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > bahoo a écrit : > > > Hi, > > > I have a text file containing a single line of text, such as > > 0024 > > > How should I read it into a "list"? > > You mean ['0024'], or ['0', '0', '2', '4'] ? > > > I tried this, but the "join" did

Re: Need help on reading line from file into list

2007-04-03 Thread Bruno Desthuilliers
bahoo a écrit : > Hi, > > I have a text file containing a single line of text, such as > 0024 > > How should I read it into a "list"? You mean ['0024'], or ['0', '0', '2', '4'] ? > I tried this, but the "join" did not work as expected. What did you expect ? help(str.join) join(...) S.joi