Processing text using python
plahey at alumni.caltech.edu
plahey at alumni.caltech.edu
Mon Feb 20 16:12:23 EST 2006
Hi,
you have plenty of good responses. I thought I would add one more:
def data_iter(file_name):
data = file(file_name)
while True:
value = data.read(3)
if not value:
break
yield value
data.close()
With the above, you can grab the entire data set (3 characters at a
time) like so:
data_set = [ d for d in data_iter('data') ]
Or iterate over it:
for d in data_iter('data'):
# do stuff
Enjoy!
More information about the Python-list
mailing list