Python code written in 1998, how to improve/change it?

Carl Cerecke cdc at maxnet.co.nz
Thu Jan 19 22:36:33 EST 2006


Carl Cerecke wrote:
> Chris Mellon wrote:
> 
>> I'm not sure why nobody else in this thread said it, but the most
>> common way of implementing state machines I've seen in Python (unless
>> theres only a couple states you can manage with if/elif) is to use a
>> dict to map states to callables.
> 
> 
> Ah. Well, my post suggested, as one option, the callables call
> each other directly.

Doh! No I didn't. And they shouldn't. Otherwise the call stack
gets out of hand. But I did suggest that each callable representing a 
state set a global variable, just before it returns, to the callable 
representing the next state to be called. Still no map required. Just a 
while loop. In any case, the function call/return is wasted cycles.

Cheers,
Carl.



More information about the Python-list mailing list