Python与Cpython [英] Python vs Cpython

查看:200
本文介绍了Python与Cpython的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于Python和CPython (Jython,IronPython)的所有大惊小怪,我不明白:

What's all this fuss about Python and CPython (Jython,IronPython), I don't get it:

python.org 提到CPython是:

python.org mentions that CPython is:


Python的传统实现(昵称为CPython)

还有另一个堆栈溢出问题提到:


CPython是Python的默认字节代码解释器,它是用C语言编写的。

老实说,我不明白这两种解释实际上是什么意思,但我想的是,如果我使用CPython,这意味着当我运行示例python代码时,它将其编译为C语言,然后像执行C代码一样执行

Honestly I don't get what both of those explanations practically mean but what I thought was that, if I use CPython does that mean when I run a sample python code, it compiles it to C language and then executes it as if it were C code

那么CPython到底是什么?与python相比它有什么区别,我应该使用CPyth吗?

推荐答案

那么CPython是什么?


CPython是原始 Python实现。它是您从Python.org下载的实现。人们称它为CPython是为了将其与其他后来的Python实现区分开来,并将语言引擎的实现与Python 编程语言本身区分开。

So what is CPython?

CPython is the original Python implementation. It is the implementation you download from Python.org. People call it CPython to distinguish it from other, later, Python implementations, and to distinguish the implementation of the language engine from the Python programming language itself.

后面是您困惑的来源;您需要将Python语言与运行 的Python代码分开。

The latter part is where your confusion comes from; you need to keep Python-the-language separate from whatever runs the Python code.

CPython happens 要在C中实现。确实,这只是实现细节。 CPython将您的Python代码(透明地)编译为字节码,并在评估循环中解释该字节码。

CPython happens to be implemented in C. That is just an implementation detail, really. CPython compiles your Python code into bytecode (transparently) and interprets that bytecode in a evaluation loop.

CPython也是第一个实现新功能的人。 Python语言开发使用CPython作为基础;其他实现如下。

CPython is also the first to implement new features; Python-the-language development uses CPython as the base; other implementations follow.

Jython IronPython PyPy 是当前的其他 Python编程语言的实现;它们分别用Java,C#和RPython(Python的子集)实现。 Jython将您的Python代码编译为 Java 字节码,因此您的Python代码可以在JVM上运行。 IronPython使您可以在 Microsoft CLR 上运行Python。而且,PyPy通过Python(的一个子集)实现,使您可以比CPython更快地运行Python代码,这应该引起您的注意。 :-)

Jython, IronPython and PyPy are the current "other" implementations of the Python programming language; these are implemented in Java, C# and RPython (a subset of Python), respectively. Jython compiles your Python code to Java bytecode, so your Python code can run on the JVM. IronPython lets you run Python on the Microsoft CLR. And PyPy, being implemented in (a subset of) Python, lets you run Python code faster than CPython, which rightly should blow your mind. :-)

因此CPython不会单独将Python代码转换为C。而是运行解释器循环。 有一个项目,它可以将Python类代码转换为C,并且名为 Cython 。 Cython为Python语言添加了一些扩展,并允许您将代码编译为C扩展,这些代码将插入 CPython解释器。

So CPython does not translate your Python code to C by itself. Instead, it runs an interpreter loop. There is a project that does translate Python-ish code to C, and that is called Cython. Cython adds a few extensions to the Python language, and lets you compile your code to C extensions, code that plugs into the CPython interpreter.

这篇关于Python与Cpython的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆