非官方的Python实现
python enasemation.jpg
Python是一种解释,交互式,面向对象的编程语言。它也可作为需要可编程接口的应用程序的扩展语言。最后,Python是便携式的:它在许多Unix变体上运行,在Mac上以及Windows 2000和更高版本上运行。
Python实施
应将Python的"实施"视为是指计划或环境,该程序或环境为执行以Python语言编写的程序提供支持,如CPYTHON参考实现所示。
有几个不同的软件包提供了我们所有人都认为是Python的软件包,尽管其中一些更像是某些现有实现的分布或变体,而不是该语言的全新实现。
Ironpython
Jython
超频
Ironpython
由C#编写的.NET和MONO的开源实现,根据Apache License 2.0许可。它依靠DLR
(动态语言运行时)。它仅支持2.7版,当前正在开发版本3。
与Cpython的差异:
与.NET框架的紧密集成。
默认情况下,字符串是Unicode。
不支持Cpython用C的扩展。
不受全球口译员锁的困扰。
性能通常较低,尽管取决于测试。
你好世界
- print "Hello World!"
您也可以使用.NET函数:
- import clr
- from System import Console
- Console.WriteLine("Hello World!")
外部链接
官方网站
GitHub存储库
Jython
根据Java编写的JVM的开源实施,根据Python Software Foundation许可证许可。它仅支持2.7版,当前正在开发版本3。
与Cpython的差异:
与JVM紧密整合。
字符串是Unicode。
不支持Cpython用C的扩展。
不受全球口译员锁的困扰。
性能通常较低,尽管取决于测试。
你好世界
打印"你好世界!"
您也可以使用Java功能:
- from java.lang import System
- System.out.println("Hello World!")
外部链接
官方网站
Mercurial存储库
超频
TransCrypt是一种将相当广泛的Python子集预编入紧凑,可读的JavaScript的工具。它具有以下特征:
允许使用Pure Python语法进行多个继承的经典OO编程,由
Cpython的本地解析器
与高质量的以网络为导向的JavaScript库的宇宙无缝集成,而是
比面向桌面的Python
基于分层URL的模块系统允许通过PYPI分布模块
Python源与生成的JavaScript代码之间的简单关系,以便于调试
带有源参考的目标代码的多级源代码和可选注释
紧凑的下载,KB S而不是MB S
优化的JavaScript代码,使用回忆(调用缓存)可选地绕过原型
查找链 运算符超载可以在本地打开和关闭,以方便可读的数字数学 代码尺寸和速度 经验表明,650 KB的Python源代码大致以相同数量的JavaScript源代码翻译。 速度与手写的JavaScript的速度匹配,如果打开呼叫的记忆,则可以超越它。 与HTML集成
- <script src="__javascript__/hello.js"></script>
- <h2>Hello demo</h2>
- <p>
- <div id = "greet">...</div>
- <button onclick="hello.solarSystem.greet ()">Click me repeatedly!</button>
- <p>
- <div id = "explain">...</div>
- <button onclick="hello.solarSystem.explain ()">And click me repeatedly too!</button>
与JavaScript和DOM集成 班级太阳系系统:
- planets =[list (chain (planet, (index + 1,))) for index, planet in enumerate ((
- ('Mercury', 'hot', 2240),
- ('Venus', 'sulphurous', 6052),
- ('Earth', 'fertile', 6378),
- ('Mars', 'reddish', 3397),
- ('Jupiter', 'stormy', 71492),
- ('Saturn', 'ringed', 60268),
- ('Uranus', 'cold', 25559),
- ('Neptune', 'very cold', 24766)
- ))]
- lines = (
- '{} is a {} planet',
- 'The radius of {} is {} km',
- '{} is planet nr. {} counting from the sun'
- )
- def __init__ (self):
- self.lineIndex = 0
- def greet (self):
- self.planet = self.planets [int (Math.random () * len (self.planets))]
- document.getElementById ('greet') .innerHTML = 'Hello {}'.format (self.planet [0])
- self.explain ()
- def explain (self):
- document.getElementById ('explain').innerHTML = (
- self.lines [self.lineIndex] .format (self.planet [0], self.planet [self.lineIndex + 1])
- )
- self.lineIndex = (self.lineIndex + 1) % 3
- solarSystem = SolarSystem ()
与其他JavaScript库集成 可以将TransCrypt与任何JavaScript库结合使用,而无需采取特殊措施或语法。 在文档中,给出了A.O.的示例。 React.js,Riot.js,Fabric.js和Node.js。 Python和JavaScript代码之间的关系 Python
- class A:
- def __init__ (self, x):
- self.x = x
- def show (self, label):
- print ('A.show', label, self.x)
- class B:
- def __init__ (self, y):
- alert ('In B constructor')
- self.y = y
- def show (self, label):
- print ('B.show', label, self.y)
- class C (A, B):
- def __init__ (self, x, y):
- alert ('In C constructor')
- A.__init__ (self, x)
- B.__init__ (self, y)
- self.show ('constructor')
- def show (self, label):
- B.show (self, label)
- print ('C.show', label, self.x, self.y)
- a = A (1001)
- a.show ('america')
- b = B (2002)
- b.show ('russia')
- c = C (3003, 4004)
- c.show ('netherlands')
- show2 = c.show
- show2 ('copy')
JavaScript
- var A = __class__ ('A', [object], {
- get __init__ () {return __get__ (this, function (self, x) {
- self.x = x;
- });},
- get show () {return __get__ (this, function (self, label) {
- print ('A.show', label, self.x);
- });}
- });
- var B = __class__ ('B', [object], {
- get __init__ () {return __get__ (this, function (self, y) {
- alert ('In B constructor');
- self.y = y;
- });},
- get show () {return __get__ (this, function (self, label) {
- print ('B.show', label, self.y);
- });}
- });
- var C = __class__ ('C', [A, B], {
- get __init__ () {return __get__ (this, function (self, x, y) {
- alert ('In C constructor');
- A.__init__ (self, x);
- B.__init__ (self, y);
- self.show ('constructor');
- });},
- get show () {return __get__ (this, function (self, label) {
- B.show (self, label);
- print ('C.show', label, self.x, self.y);
- });}
- });
- var a = A (1001);
- a.show ('america');
- var b = B (2002);
- b.show ('russia');
- var c = C (3003, 4004);
- c.show ('netherlands');
- var show2 = c.show;
- show2 ('copy');
评论已关闭