What is the Pythonic way to implement a simple FSM?

后端 未结 7 1638
猫巷女王i
猫巷女王i 2021-01-31 21:50

Yesterday I had to parse a very simple binary data file - the rule is, look for two bytes in a row that are both 0xAA, then the next byte will be a length byte, then skip 9 byte

7条回答
  •  独厮守ぢ
    2021-01-31 22:44

    I think your solution looks fine, except you should replace count = count - 1 with count -= 1.

    This is one of those times where fancy code-show-offs will come up ways of have dicts mapping states to callables, with a small driver function, but it isn't better, just fancier, and using more obscure language features.

提交回复
热议问题