Scanning a file character by character

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Mon Feb 9 22:49:03 EST 2009


On Mon, 09 Feb 2009 19:10:28 -0800, Spacebar265 wrote:

> How would I do separate lines into words without scanning one character
> at a time?

Scan a line at a time, then split each line into words.


for line in open('myfile.txt'):
    words = line.split()


should work for a particularly simple-minded idea of words.



-- 
Steven



More information about the Python-list mailing list