How exactly is Python Bytecode Run in CPython?

前端 未结 3 2081
逝去的感伤
逝去的感伤 2020-12-04 06:48

I am trying to understand how Python works (because I use it all the time!). To my understanding, when you run something like python script.py, the script is converted to by

3条回答
  •  半阙折子戏
    2020-12-04 07:10

    Yes, your understanding is correct. There is basically (very basically) a giant switch statement inside the CPython interpreter that says "if the current opcode is so and so, do this and that".

    http://hg.python.org/cpython/file/3.3/Python/ceval.c#l790

    Other implementations, like Pypy, have JIT compilation, i.e. they translate Python to machine codes on the fly.

提交回复
热议问题