I don't really get the concept of "bytecode interpreter" in the context of CPython. Can someone shed some light over the whole picture?
Does it mean that CPython will compile and execute pyc file (bytecode file?). Then what compile py file to pyc file? And how is Jython different from CPython (except they are implemented in different languages).
I also read somewhere that Python is C++ interpretation. Is this correct? And what does that mean?
I'm still very new to Python, so forgive me if I ask the dumb questions... Thank you so much!
CPython is the implementation of Python in C. It's the first implementation, and still the main one that people mean when they talk about Python. It compiles .py files to .pyc files. .pyc files contain bytecodes. The CPython implementation also interprets those bytecodes. CPython is not written in C++, it is C.
The compilation from .py to .pyc happens transparently as needed. When you execute a .py file, it will first be compiled to a .pyc file if needed, then the .pyc file will be interpreted.
Jython is different because (in addition to being implemented in Java instead of C) it compiles .py files into .class files so they can be executed in the JVM.
First: The fact that CPython is a bytecode interpreter should not matter to you as a user of python. Go ahead and write code, and don't worry about how it's turned into action.
So, to answer your question and satisfy your curiosity, here is what happens: CPython reads python source code, and compiles it into python byte code, which is stored in the .pyc file. It then executes that code using a bytecode interpreter. This design separates the parsing of python from the execution, allowing both parts of the interpreter to be simpler.
Jython is only the front half -- it reads Python source, and outputs Java bytecodes, which are then interpreted by the JVM. It's the same architecture as CPython, with two noteworthy differences: One: the java bytecode is standardized and documented, while the CPython bytecode is considered internal to python, and can change at any time. Two: the JVM is a whole lot more complicated than the CPython interpreter. The JVM has one of the most advanced JIT engines in the world, while the CPython interpreter is pretty simple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With