streaming a file object through re.finditer
Daniel Bickett
dbickett at gmail.com
Wed Feb 2 21:13:48 EST 2005
The following example loads the file into memory only one line at a
time, so it should suit your purposes:
>>> data = file( "important.dat" , "w" )
>>> data.write("this\nis\nimportant\ndata")
>>> data.close()
now read it....
>>> import re
>>> data = file( "important.dat" , "r" )
>>> line = data.readline()
>>> while line:
for x in re.finditer( "\w+" , line):
print x.group()
line = data.readline()
this
is
important
data
>>>
--
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
More information about the Python-list
mailing list