Need help on reading line from file into list

Mel Wilson mwilson at the-wire.com
Wed Apr 4 06:56:37 CEST 2007


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('source.txt').readlines()" is defaulted to "str?

You can do without.

[x.strip() for x in open ('source.txt', 'r')]

will also work.

	Cheers,		Mel.





More information about the Python-list mailing list