Python processing of an input byte stream

Erno Kuusela erno-news at erno.iki.fi
Mon Oct 30 18:46:13 EST 2000


 | 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



More information about the Python-list mailing list