Peter Otten wrote: > Not clumsy, just slow.
As you wish ;o) I didn't mean clumsy as in "clumsy looking Python code" anyway, rather as in "clumsy to use the Python machinery for operations that are straight-forward and efficient in C, in which language str and cStringIO are implemented already". > I hope you'll let us know how much faster your > final approach turns out to be. I'm pretty convinced that implementing an algorithmically nice state machine that goes through a string char by char won't get any faster than using s[index] all the time unless I do a frankenstring in C. Failing that, a more pragmatic approach is what Andreas suggests; see the other subthread. > By the way, I'll consider anything that > doesn't implement seek() and tell() cheating :-) An implementation of frankenstring would have to have seek and tell, that's the point of doing it. But for half-way simple state machines, hiding the index handling in a Python class that slows things down it just not worth it. Doing index += 1 here and there is fine if it happens only half a dozen times. I know it's not beautiful, that's why I started this thread ;o) -- Thomas -- http://mail.python.org/mailman/listinfo/python-list