[EMAIL PROTECTED] wrote: > I think implementing a finite state automaton would be a good (best?) > solution. I have drawn a FSM for you (try viewing the following in > fixed width font). Just increment the count when you reach state 5. > > <---------------| > | | > 0 0 | 1 0 |0 > -->[1]--->[2]--->[3]--->[4]--->[5]-| > ^ | | ^ | | | > 1| |<---| | | |1 |1 > |_| 1 |_| | | > ^ 0 | | > |---------------------|<-----| > > If you don't understand FSM's, try getting a book on computational > theory (the book by Hopcroft & Ullman is great.) > > Here you don't have special cases whether reading in blocks or reading > whole at once (as you only need one byte at a time). > Indeed, but reading one byte at a time is about the slowest way to process a file, in Python or any other language, because it fails to amortize the overhead cost of function calls over many characters.
Buffering wasn't invented because early programmers had nothing better to occupy their minds, remember :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list