Python is implemented in several other languages

  • 2020-04-02 14:31:04
  • OfStack

Python itself, as a programming language, has multiple implementations. The implementation here refers to Python interpreters and standard libraries that conform to the Python language specification. These implementations, while implementing the same language, are somewhat different from each other, especially from CPython.

The main implementations are listed below.

1. Retaining: This is the official version of Python, implemented in C, which is the most widely used, and where new language features typically appear first.

The CPython implementation converts the source file (py file) into a bytecode file (pyc file) and runs it on the Python virtual machine.

2. Jython: This is a Java implementation of Python, which is much more interoperable with the Java language than CPython is with the C language.

You can use the Java code base directly in Python, which makes it easy to write test code for Java programs using Python, and further, you can write GUI programs in Python using graphical libraries such as Swing.

Jython dynamically compiles Python code into Java bytecode and then runs the converted program on the JVM, which means that the Python program is no different than the Java program, except for the source code.

It's easy to write a class in Python and use it like a Java class.

You can even statically compile Jython scripts into Java bytecode.

Sample code:


from java.lang import System
System.out.write('Hello World!n')

3. Python for. NET: It is essentially a managed version of.net implemented by CPython and has good interoperability with.net libraries and program code.

4.IronPython: unlike Python for.net, it is a C# implementation of Python, and it compiles Python code into C# intermediate code (similar to Jython) and runs it, and it interoperates very well with the.net language.

5. PyPy: The Python version of Python works like this: PyPy runs on CPython (or some other implementation) and user programs run on PyPy. One of its goals is to be a testing ground for the Python language itself, because the implementation of the PyPy interpreter can be easily modified (because it is written in Python).

6. Stackless: One limitation of CPython is that every Python function call produces a C function call. This means that simultaneous function calls are limited, making it difficult for Python to implement user-level thread libraries and complex recursive applications. Once this limit is exceeded, the program crashes. Stackless's Python implementation breaks this limitation by allowing any number of Python stack frames to be held in a single C stack frame. This way you can have an almost infinite number of function calls and support a huge number of threads. The only problem with Stackless is that it makes major changes to the existing CPython interpreter. So it's almost a separate branch. Another project, called Greenlets, also supports tasklets. It is a standard C extension and therefore does not require any changes to the standard Python interpreter.


Related articles: