Need help on reading line from file into list
mwilson at the-wire.com
Wed Apr 4 00:56:37 EDT 2007
[ ... ]
> 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.
More information about the Python-list