Frankenstring
ucntcme at gmail.com
ucntcme at gmail.com
Thu Jul 14 17:31:07 EDT 2005
>jay graves wrote:
>> see StringIO or cStringIO in the standard library.
> Just as with files, iterating over them returns whole lines, which is
> unfortunately not what I want.
Then why not subclass it and alter the iteration scheme to do a read(1)
or something?
from StringIO import StringIO
class FrankenString(StringIO):
lastidx = 0
atEnd = False
def __iter__(self):
while not self.atEnd:
char = self.read(1)
idx = self.tell()
if self.lastidx == idx:
self.atEnd = True
self.lastidx = idx
yield char
More information about the Python-list
mailing list