title: `goto` in Python
body: <p>I must use <code>goto</code> in Python. I found <a href="http://entrian.com/goto/" rel="nofollow noreferrer">entrians <code>goto</code></a> but my Python implementation (CPython 2.7.1 on Mac) does not have this module, so it doesn't seem to be portable. It should at least work in all Python implementations which support CPython bytecode (esp. I care about CPython and PyPy). Then there is <a href="https://stackoverflow.com/questions/438844/is-there-a-label-goto-in-python">this related question</a>, and <a href="https://github.com/cdjc/goto" rel="nofollow noreferrer">cdjc's <code>goto</code></a>. And the ones given by answers below.</p>
  
  <p>I could go and build up the bytecode manually (i.e. write my own Python compiler) because there is such an instruction (<code>JUMP_ABSOLUTE</code> and friends). But I wonder if there is an easier way. Is it possible via <code>inspect</code> or so to call a single bytecode instruction? I also thought about compiling via Python and then automatically patching the generated Python bytecode.</p>
  
  <hr>
  
  <p>Of course, people will ask why and will not give me any helpful answer if I don't explain why I really really need this. So in short my use case: I am translating a C AST to Python AST and compiling this. I can map every logical flow (all the loops and other stuff) in some way to equivalent Python code. Everything except <code>goto</code>. Related projects: <a href="https://github.com/albertz/PyCParser" rel="nofollow noreferrer">PyCParser</a> (see <a href="https://github.com/albertz/PyCParser/blob/master/interpreter.py" rel="nofollow noreferrer"><code>interpreter.py</code></a>), <a href="https://github.com/albertz/PyCPython" rel="nofollow noreferrer">PyCPython</a>, <a href="https://github.com/albertz/PyLua" rel="nofollow noreferrer">PyLua</a>.</p>