streaming a file object through re.finditer

Erick idadesub at gmail.com
Wed Feb 2 21:10:14 EST 2005


Ack, typo. What I meant was this:
cat a b c > blah

>>> import re
>>> for m in re.finditer('\w+', file('blah')):

...   print m.group()
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: buffer object expected

Of course, this works fine, but it loads the file completely into
memory (right?):
>>> for m in re.finditer('\w+', file('blah').read()):
...   print m.group()
...
a
b
c




More information about the Python-list mailing list