Re: Frankenstring
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Frankenstring

From: <ucntcme@gmail.com>
Date: Thu Jul 14 2005 - 23:55:45 CEST

Here is a cStringIO based version:
class FrankenString:
        def __init__(self,string=None):
                self.str = StringIO(string)
                self.atEnd = False
                self.lastidx = 0
                self.seek = self.str.seek
                self.tell = self.str.tell
        def __iter__(self):
                while not self.atEnd:
                        char = self.str.read(1)
                        idx = self.str.tell()
                        if self.lastidx == idx:
                                self.atEnd = True
                        self.lastidx = idx
                        yield char

On a string 1024*1024 long the StringIO version takes 10s to iterate
over but do nothing, whereas this one takes 3.1 on my system. Well to
create that string, create the instance and loop over. But since each
variant is doing the same thing I figure it's even. ;)
Received on Thu Sep 29 16:57:35 2005