473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,401 developers and data experts.

Non-official Python Implementations

Python Implementations.jpgPython is an interpreted, interactive, object-oriented programming language. It is also usable as an extension language for applications that need a programmable interface. Finally, Python is portable: it runs on many Unix variants, on the Mac, and on Windows 2000 and later.

Python Implementations

An "implementation" of Python should be taken to mean a program or environment which provides support for the execution of programs written in the Python language, as represented by the CPython reference implementation.

There have been and are several distinct software packages providing of what we all recognize as Python, although some of those are more like distributions or variants of some existing implementation than a completely new implementation of the language.
  1. IronPython
  2. Jython
  3. Transcrypt

IronPython

Open-source implementation for .NET and Mono written in C#, licensed under Apache License 2.0. It relies on DLR
(Dynamic Language Runtime). It supports only version 2.7, version 3 is currently being developed.

Differences with CPython:
  • Tight integration with .NET Framework.
  • Strings are Unicode by default.
  • Does not support extensions for CPython written in C.
  • Does not suffer from Global Interpreter Lock.
  • Performance is usually lower, though it depends on tests.

Hello World

Expand|Select|Wrap|Line Numbers
  1. print "Hello World!"
You can also use .NET functions:

Expand|Select|Wrap|Line Numbers
  1. import clr
  2. from System import Console
  3. Console.WriteLine("Hello World!")
External links
  • Official website
  • GitHub repository

Jython

Open-source implementation for JVM written in Java, licensed under Python Software Foundation License. It supports only version 2.7, version 3 is currently being developed.

Differences with CPython:
  • Tight integration with JVM.
  • Strings are Unicode.
  • Does not support extensions for CPython written in C.
  • Does not suffer from Global Interpreter Lock.
  • Performance is usually lower, though it depends on tests.

Hello World

print "Hello World!"

You can also use Java functions:

Expand|Select|Wrap|Line Numbers
  1. from java.lang import System
  2. System.out.println("Hello World!")
  3.  
External links
  • Official website
  • Mercurial repository

Transcrypt

Transcrypt is a tool to precompile a fairly extensive subset of Python into compact, readable Javascript. It has the following characteristics:
  • Allows for classical OO programming with multiple inheritance using pure Python syntax, parsed by
    CPython’s native parser
  • Seamless integration with the universe of high-quality web-oriented JavaScript libraries, rather
    than the desktop-oriented Python ones
  • Hierarchical URL based module system allowing module distribution via PyPi
  • Simple relation between Python source and generated JavaScript code for easy debugging
  • Multi-level sourcemaps and optional annotation of target code with source references
  • Compact downloads, kB’s rather than MB’s
  • Optimized JavaScript code, using memoization (call caching) to optionally bypass the prototype
    lookup chain
  • Operator overloading can be switched on and off locally to facilitate readable numerical math

Code size and speed

Experience has shown that 650 kB of Python source code roughly translates in the same amount of JavaScript source code. The speed matches the speed of handwritten JavaScript and can surpass it if call memoizing is switched on.

Integration with HTML

Expand|Select|Wrap|Line Numbers
  1. <script src="__javascript__/hello.js"></script>
  2. <h2>Hello demo</h2>
Expand|Select|Wrap|Line Numbers
  1. <p>
  2. <div id = "greet">...</div>
  3. <button onclick="hello.solarSystem.greet ()">Click me repeatedly!</button>
Expand|Select|Wrap|Line Numbers
  1. <p>
  2. <div id = "explain">...</div>
  3. <button onclick="hello.solarSystem.explain ()">And click me repeatedly too!</button>
Integration with JavaScript and DOM

class SolarSystem:

Expand|Select|Wrap|Line Numbers
  1. planets =[list (chain (planet, (index + 1,))) for index, planet in enumerate ((
  2.  ('Mercury', 'hot', 2240),
  3.  ('Venus', 'sulphurous', 6052),
  4.  ('Earth', 'fertile', 6378),
  5.  ('Mars', 'reddish', 3397),
  6.  ('Jupiter', 'stormy', 71492),
  7.  ('Saturn', 'ringed', 60268),
  8.  ('Uranus', 'cold', 25559),
  9.  ('Neptune', 'very cold', 24766)
  10.  ))]
Expand|Select|Wrap|Line Numbers
  1. lines = (
  2.  '{} is a {} planet',
  3.  'The radius of {} is {} km',
  4.  '{} is planet nr. {} counting from the sun'
  5.  )
Expand|Select|Wrap|Line Numbers
  1. def __init__ (self):
  2.  self.lineIndex = 0
Expand|Select|Wrap|Line Numbers
  1. def greet (self):
  2.  self.planet = self.planets [int (Math.random () * len (self.planets))]
  3.  document.getElementById ('greet') .innerHTML = 'Hello {}'.format (self.planet [0])
  4.  self.explain ()
Expand|Select|Wrap|Line Numbers
  1.  def explain (self):
  2.  document.getElementById ('explain').innerHTML = (
  3.  self.lines [self.lineIndex] .format (self.planet [0], self.planet [self.lineIndex + 1])
  4.  )
  5.  self.lineIndex = (self.lineIndex + 1) % 3
  6.  solarSystem = SolarSystem ()
  7.  
Integration with other JavaScript libraries

Transcrypt can be used in combination with any JavaScript library without special measures or syntax. In the documentation, examples are given for a.o. react.js, riot.js, fabric.js and node.js.

Relation between Python and JavaScript code

Python

Expand|Select|Wrap|Line Numbers
  1. class A:
  2.  def __init__ (self, x):
  3.  self.x = x
  4.  def show (self, label):
  5.  print ('A.show', label, self.x)
  6.  
  7. class B:
  8.  def __init__ (self, y):
  9.  alert ('In B constructor')
  10.  self.y = y
  11.  
  12.  def show (self, label):
  13.  print ('B.show', label, self.y)
  14.  
  15. class C (A, B):
  16.  def __init__ (self, x, y):
  17.  alert ('In C constructor')
  18.  A.__init__ (self, x)
  19.  B.__init__ (self, y)
  20.  self.show ('constructor')
  21.  
  22.  def show (self, label):
  23.  B.show (self, label)
  24.  print ('C.show', label, self.x, self.y)
  25.  
  26. a = A (1001)
  27. a.show ('america')
  28. b = B (2002)
  29. b.show ('russia')
  30. c = C (3003, 4004)
  31. c.show ('netherlands')
  32. show2 = c.show
  33. show2 ('copy')
JavaScript

Expand|Select|Wrap|Line Numbers
  1. var A = __class__ ('A', [object], {
  2.  get __init__ () {return __get__ (this, function (self, x) {
  3.  self.x = x;
  4.  });},
  5.  get show () {return __get__ (this, function (self, label) {
  6.  print ('A.show', label, self.x);
  7.  });}
  8. });
  9. var B = __class__ ('B', [object], {
  10.  get __init__ () {return __get__ (this, function (self, y) {
  11.  alert ('In B constructor');
  12.  self.y = y;
  13.  });},
  14.  get show () {return __get__ (this, function (self, label) {
  15.  print ('B.show', label, self.y);
  16.  });}
  17. });
  18. var C = __class__ ('C', [A, B], {
  19.  get __init__ () {return __get__ (this, function (self, x, y) {
  20.  alert ('In C constructor');
  21.  A.__init__ (self, x);
  22.  B.__init__ (self, y);
  23.  self.show ('constructor');
  24.  });},
  25.  get show () {return __get__ (this, function (self, label) {
  26.  B.show (self, label);
  27.  print ('C.show', label, self.x, self.y);
  28.  });}
  29. });
  30. var a = A (1001);
  31. a.show ('america');
  32. var b = B (2002);
  33. b.show ('russia');
  34. var c = C (3003, 4004);
  35. c.show ('netherlands');
  36. var show2 = c.show;
  37. show2 ('copy');
Mar 13 '19 #1
1 2929
Useful. Included one I haven't heard of yet.

I'm following PyPy and very possibly migrating to it from cpython eventually.
Mar 28 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
46
by: Jon Perez | last post by:
Can one run a 1.5 .pyc file with the 2.x version interpreters and vice versa? How about running a 2.x .pyc using a 2.y interpreter?
28
by: Maboroshi | last post by:
Hi I am fairly new to programming but not as such that I am a total beginner From what I understand C and C++ are faster languages than Python. Is this because of Pythons ability to operate on...
217
by: gyromagnetic | last post by:
The following url points to an article written by Damian Conway entitled "Ten Essential Development Practices": http://www.perl.com/pub/a/2005/07/14/bestpractices.html Althought the article has...
34
by: Ville Voipio | last post by:
I would need to make some high-reliability software running on Linux in an embedded system. Performance (or lack of it) is not an issue, reliability is. The piece of software is rather simple,...
118
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
69
by: Edward K Ream | last post by:
The pros and cons of making 'print' a function in Python 3.x are well discussed at: http://mail.python.org/pipermail/python-dev/2005-September/056154.html Alas, it appears that the effect of...
25
by: John Nagle | last post by:
Some faster Python implementations are under development. JPython has been around for a while, and PyPy and ShedSkin continue to move forward. It's worth thinking about what slows down Python...
0
by: Paddy | last post by:
Hi, I'm wanting to update the Wikipedia entry on doctest with information on which current python implementations support the doctest module. So, does Doctest come with ironpython, jython, python...
53
by: Vicent Giner | last post by:
Hello. I am new to Python. It seems a very interesting language to me. Its simplicity is very attractive. However, it is usually said that Python is not a compiled but interpreted programming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.