Result: Recreating Goto in Python: How and Why
Further Information
The Python language has no unrestricted goto statement, but because of Python’s deep introspection capabilities, along with its dynamic nature, an unrestricted goto can be added to the language by rewriting a function’s bytecode at runtime. Two primary use cases for goto in Python are discussed: porting existing historic code to Python while maintaining the existing code’s flavour, and implementing state machines. While theoretically unnecessary, goto can make the first case easier, and the second case faster. An implementation is described and performance tests on an example state machine show using goto is a very fast method of implementing state machines in Python, and existing efforts to port historic code are already using the goto implementation.