Bengt Richter wrote:
> On Thu, 19 Jan 2006 23:16:57 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote:

> How about something like
> 
>  >>> actions = dict(
>  ...    a=compile('print "A"; state="b"','','exec'),
>  ...    b=compile('print "B"; state="c"','','exec'),
>  ...    c=compile('print "C"; state=None','','exec')
>  ... )
>  >>> state = 'a'
>  >>> while state: eval(actions[state])
>  ...
>  A
>  B
>  C

Good idea. But we can eliminate the dictionary lookup:

a1 = compile('print "A"; state=b1','','exec')
b1 = compile('print "B"; state=c1','','exec')
c1 = compile('print "C"; state=None','','exec')

state = a1
while state:
     eval(state)


Cheers,
Carl
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to