Reading a file, sans whitespace
Konstantin Veretennicov
kveretennicov at yahoo.com
Mon May 24 09:59:54 EDT 2004
"Michael Geary" <Mike at DeleteThis.Geary.com> wrote in message news:<10b2dvrfqhmbm5a at corp.supernews.com>...
>
> import re
> reWhitespace = re.compile( '\s+' )
> for line in file( 'inputFile' ).readlines():
> print reWhitespace.split( line.strip() )
>
> But for a large file, the second version will be faster because the regular
And you'll want to use "for line in file('inputFile')"
instead of "for line in file('inputFile').readlines()",
especially for large files ;)
- kv
More information about the Python-list
mailing list