本文翻译自:Python vs Cpython

What's all this fuss about Python and CPython (Jython,IronPython) , I don't get it: 什么是关于Python和CPython (Jython,IronPython)的所有这些大惊小怪,我不明白:

python.org mentions that CPython is: python.org提到CPython是:

The "traditional" implementation of Python (nicknamed CPython) Python的“传统”实现(绰号CPython)

yet another Stack Overflow question mentions that: 另一个Stack Overflow问题提到:

CPython is the default byte-code interpreter of Python, which is written in C. CPython是Python的默认字节码解释器,用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代码时,它将它编译为C语言,然后执行它就好像它是C码

So what exactly is CPython and how does it differ when compared with python and should I probably use CPython over Python and if so what are its advantages? 那么CPython究竟是什么呢?与python相比它有何不同?我是否应该使用CPython而不是Python,如果有的话,它的优点是什么?


#1楼

参考:https://stackoom.com/question/19sY3/Python-vs-Cpython


#2楼

So what is CPython? 那么CPython是什么?

CPython is the original Python implementation. CPython是最初的 Python实现。 It is the implementation you download from Python.org. 这是您从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. 人们将其称为CPython,以区别于其他后来的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. 你需要将Python-the-language与运行 Python代码的任何东西分开。

CPython happens to be implemented in C. That is just an implementation detail, really. CPython 恰好用C实现。这只是一个实现细节,真的。 CPython compiles your Python code into bytecode (transparently) and interprets that bytecode in a evaluation loop. CPython将您的Python代码编译为字节码(透明地)并在评估循环中解释该字节码。

CPython is also the first to implement new features; CPython也是第一个实现新功能的人; Python-the-language development uses CPython as the base; Python-the-language开发使用CPython作为基础; other implementations follow. 其他实现如下。

What about Jython, etc.? Jython等怎么样?

Jython , IronPython and PyPy are the current "other" implementations of the Python programming language; Jython , IronPython和PyPy是Python编程语言的当前“其他”实现; these are implemented in Java, C# and RPython (a subset of Python), respectively. 它们分别在Java,C#和RPython(Python的一个子集)中实现。 Jython compiles your Python code to Java bytecode, so your Python code can run on the JVM. Jython将您的Python代码编译为Java字节码,因此您的Python代码可以在JVM上运行。 IronPython lets you run Python on the Microsoft CLR . IronPython允许您在Microsoft CLR上运行Python。 And PyPy, being implemented in (a subset of) Python, lets you run Python code faster than CPython, which rightly should blow your mind. PyPy是在Python的(子集)中实现的,它允许您比CPython更快地运行Python代码,这应该让您大吃一惊。 :-) :-)

Actually compiling to C 实际编译为C

So CPython does not translate your Python code to C by itself. 因此CPython的本身不翻译你的Python代码转换为C。 Instead, it runs an interpreter loop. 相反,它运行一个解释器循环。 There is a project that does translate Python-ish code to C, and that is called Cython . 目前的Python翻译-ISH代码转换为C的一个项目,那就是所谓的用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. 用Cython增加了一些扩展Python语言,并让您编译代码,以C扩展,可以插入 CPython的解释器代码。


#3楼

implementation means what language was used to implement Python and not how python Code would be implemented. implementation意味着使用什么语言来实现Python,而不是如何实现python Code。 The advantage of using CPython is the availability of C Run-time as well as easy integration with C/C++. 使用CPython的优点是C Run-time的可用性以及与C / C ++的轻松集成。

So CPython was originally implemented using C . 所以CPython最初是用C实现的。 There were other forks to the original implementation which enabled Python to lever-edge Java (JYthon) or .NET Runtime (IronPython). 原始实现还有其他分支,使Python能够利用Java(JYthon)或.NET Runtime(IronPython)。

Based on which Implementation you use, library availability might vary, for example Ctypes is not available in Jython , so any library which uses ctypes would not work in Jython. 根据您使用的实现,库可用性可能会有所不同,例如Ctypes在Jython中不可用 ,因此任何使用ctypes的库都无法在Jython中使用。 Similarly, if you want to use a Java Class, you cannot directly do so from CPython. 同样,如果要使用Java类,则无法直接从CPython执行此操作。 You either need a glue (JEPP) or need to use Jython (The Java Implementation of Python) 你需要一个胶水(JEPP)或需要使用Jython(Python的Java实现)


#4楼

Python is a language: a set of rules that can be used to write programs. Python是一种语言:一组可用于编写程序的规则。 There are several implementaions of this language. 这种语言有几种实现方式。

No matter what implementation you take, they do pretty much the same thing: take the text of your program and interpret it, executing its instructions. 无论你采取什么样的实现,它们都做同样的事情:获取程序的文本并解释它,执行它的指令。 None of them compile your code into C or any other language. 他们都没有将您的代码编译成C或任何其他语言。

CPython is the original implementation, written in C. (The "C" part in "CPython" refers to the language that was used to write Python interpreter itself.) CPython是用C编写的原始实现。(“CPython”中的“C”部分指的是用于编写Python解释器本身的语言。)

Jython is the same language (Python), but implemented using Java. Jython是相同的语言(Python),但使用Java实现。

IronPython interpreter was written in C#. IronPython解释器是用C#编写的。

There's also PyPy - a Python interpreter written in Python. 还有PyPy - 一个用Python编写的Python解释器。 Make your pick :) 你的选择:)


#5楼

You need to distinguish between a language and an implementation. 您需要区分语言和实现。 Python is a language, Python是一种语言,

According to Wikipedia , "A programming language is a notation for writing programs, which are specifications of a computation or algorithm". 根据维基百科 ,“编程语言是编写程序的符号,它是计算或算法的规范”。 This means that it's simply the rules and syntax for writing code. 这意味着它只是编写代码的规则和语法。 Separately we have a programming language implementation which in most cases, is the actual interpreter or compiler. 另外,我们有一个编程语言实现 ,在大多数情况下,它是实际的解释器或编译器。

Python is a language. Python是一种语言。 CPython is the implementation of Python in C. Jython is the implementation in Java, and so on. CPython是C中Python的实现.Jython是Java中的实现,依此类推。

To sum up: You are already using CPython (if you downloaded from here ). 总结一下:您已经在使用CPython(如果您从此处下载)。


#6楼

You should know that CPython doesn't really support multithreading because of the Global Interpreter Lock . 您应该知道,由于Global Interpreter Lock ,CPython并不真正支持多线程。 It also has no Optimisation mechanisms for recursion, and has many other limitations that other implementations and libraries try to fill. 它也没有用于递归的优化机制,并且还有许多其他实现和库试图填充的其他限制。

You should take a look at this page on the python wiki. 你应该看看python wiki上的这个页面 。

Look at the code snippets on this page, it'll give you a good idea of what an interpreter is. 看看这个页面上的代码片段,它会让你很好地了解解释器是什么。

Python vs Cpython相关推荐

  1. python解释器cpython的源码简要介绍

    0. 参考文档 参考文档如下: Your Guide to the CPython Source Code [python]带你入门cpython源代码,让你不再一头雾水!尝试去读读python的实现 ...

  2. python、cpython、IPython、Jython区别

    python.cpython.IPython.Jython小谈 python CPython IPython Jython python Python是解释型语言,代码在执行时会一行一行地翻译成CPU ...

  3. python和c-python和C的如何实现互相调用?

    本文和大家分享的是python和c的互相调用相关知识,一起来看看吧,希望对大家学习python有所帮助. 最近在考虑基于udp做一个用于网游战斗中的数据同步协议,为了前期测试数据,决定先做一个外部的代 ...

  4. python和c-Python与C的简单比较(Python3.0)

    Python可以说是目前最火的语言之一了,人工智能的兴起让Python一夜之间变得家喻户晓,Python号称目前最最简单易学的语言,现在有不少高校开始将Python作为大一新生的入门语言.本萌新也刚开 ...

  5. 【Python】CPython解释器及字节码

    看了set和dict,看到了字节码和dis模块,看了字节码又不能不看python解释器,很多东西都是相互关联想通.看了一篇文章https://www.cnblogs.com/nelsen-chen/p ...

  6. Python, CPython, Pypy, Jython的简单介绍

    简单地说,Python是一门编程语言,任何一种编程语言都需要用另一种语言来实现它,比如C语言就是用机器语言来实现的.所以,Python根据实现方式不同分为了CPyhton.Pypy.Jython等. ...

  7. python减小内存占用_如何将Python内存占用缩小20倍?

    当程序执行过程中RAM中有大量对象处于活动状态时,可能会出现内存问题,特别是在对可用内存总量有限制的情况下. 下面概述了一些减小对象大小的方法,这些方法可以显著减少纯Python程序所需的RAM数量. ...

  8. java中调用python

    在Java中调用Python </h1><div class="clear"></div><div class="postBod ...

  9. Python:urllib2模块的基本使用

    urllib2库的基本使用 所谓网页抓取,就是把URL地址中指定的网络资源从网络流中读取出来,保存到本地. 在Python中有很多库可以用来抓取网页,我们先学习urllib2. urllib2 是 P ...

最新文章

  1. keras中重要的函数用法及参数详解
  2. 为何 NLP 领域难以出现“独角兽”?
  3. Linux sendmail 服务器
  4. 电脑下载的M4A格式文件怎么转换为MP3格式
  5. 2021年度618品牌营销分析报告
  6. CodeForces 468 CHack it!
  7. 在桌面应用中使用JAVA DB[组图]
  8. 力扣 两两交换链表中的节点
  9. c# 声音控制(转载)
  10. Atitit 架构师的技术框架体系图 各种引擎列表 脚本引擎 groovy beanshel php nodejs rhino等 表达式引擎技术 Ognl/MVELl等 通讯, rest 命令解
  11. python在d盘创建txt文件_python中如何创建一个txt文件
  12. 解决:windows电脑连接iphone手机热点,iphone锁屏后热点会自动断开
  13. iOS 9的App Thinning方案如何节省存储空间
  14. (5)完整的Django框架学习之自定义过滤器及标签
  15. java权限控制是什么_论Java访问权限控制的重要性
  16. 哈尔滨工业大学计算机考研资料汇总
  17. 送书【新书】 |《Git从入门到精通》
  18. HDUOJ 1114 Piggy-Bank
  19. HTML实训实训心得
  20. 嵌入式实践教程--ASOC之Codec

热门文章

  1. cocos2dx 3.x(移动修改精灵坐标MoveTo与MoveBy)
  2. UVa11988 Broken Keyboard (a.k.a. Beiju Text)
  3. javascript三元操作符
  4. 分享bootstrap3.0.2响应式模板-第三弹[Metronic_Admin]
  5. ORA-00018-超出最大连接数
  6. docker技术之基本命令
  7. MFCC/Filter Bank的提取流程
  8. 使用Xcode7的Instruments检测解决iOS内存泄露
  9. 中国海洋大学第四届朗讯杯高级组 A 2718 Rocky(模拟)
  10. Windows下MySQL的详细安装教程