Python processing of an input byte stream

apighin at my-deja.com apighin at my-deja.com
Mon Oct 30 21:55:29 EST 2000


Wow!  This is great.  I will play with this tomorrow morning.  If it
really is this straight forward, then Python is one seriously powreful
tool.  Thanks again!

In article <ku66m9gaey.fsf at lasipalatsi.fi>,
  Erno Kuusela <erno-news at erno.iki.fi> wrote:
>  | import sys, time
>  | ops = {
>  |     0x1 : lambda: 'Function (main) initialized',
>  |     0x2 : lambda a: "Key '%s' was pressed" % a,
>  |     # etc.
>  | }
>
>  | while 1:
>  |     c = sys.stdin.read(1)
>  |     if not c:
>
> probably works better if you replace the below 2 lines...
>
>  |         time.sleep(1)
>  |         continue
>
> ... with
>            break
>
> :)
>
>  |     op = ops[c]
>  |     nargs = op.func_code.co_argcount
>  |     args = tuple(sys.stdin.read(nargs))
>  |     print apply(op, args)
>
>   -- erno
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list