Python processing of an input byte stream

William Park parkw at better.net
Mon Oct 30 17:15:36 EST 2000


On Mon, Oct 30, 2000 at 09:23:47PM +0000, apighin at my-deja.com wrote:
> First off, I have to admit that I am entirely new
> to Python.  I had been looking at possible ways
> of approaching a task (to be outlined soon) and
> had more or less settled on Perl, when it was
> suggested: 'NO! Python, Python, Python! It's MUCH
> better.'  So here I am, eliciting help.
> 
> Here is what I am trying to accomplish:  I am
> trying to do processing on an incoming byte
> stream, according to a template.  The template
> would, in my mind (but not necessarily) be
> something similar to the 'printf' formatting
> codes for C.  The input byte stream would be
> continuous, so the Python module should expect an
> EOF, similar to running 'tail -f'.
> 
> For example, an input byte of '0x1' might
> translate to 'Function (main) initialized'.  An
> input byte might translate to 'A key was pressed,
> that key was ?' where ? would come from the next
> byte in the stream.  This means that the routine
> would need to have an understanding that some
> mappings have parameters associated, and other do
> not.  This is sort of turning into an FSM.
> 
> I took a quick look at Compiling Little Languages
> in Python (John Aycock) from the www.python.org
> Website, and that outlines one possible direction.
> 
> I'd really like to know if this is Python's
> forte, if I should look somewhere else (where!?),
> and best of all, if this is already done!
> 
> Thanks very much in advance,
> Anthony

Reading input stream is no brainer; you can do that with any language.
Most of the effort would be in handling the variable length formats.  I
would think (one or more) dictionary would be ideal for this kind of
"table lookup".

---William Park, Open Geometry Consulting




More information about the Python-list mailing list