Python and JavaScript code conversion tools, pythonjavascript

Source: Internet
Author: User

Python and JavaScript code conversion tools, pythonjavascript

Select Python or JavaScript? Although many friends are still arguing about who is more powerful and who has a brighter development prospects, there is no doubt that the competition between the two has a clear answer in the Web Front-end field. Based on the browser platform, if JavaScript is abandoned, there will be no projects to choose from.

Okay, maybe the answer is not that absolute. JavaScript has become a conversion target for many other programming languages (related examples include TypeScript, Emscripten, Cor, and Cheerp ). Python has a large followers group, and the existing powerful library resources make it an ideal JavaScript-oriented option to be converted or translated.

Here are four projects that can smoothly bring Python into the JavaScript world. One of them is highlighted by the flexible bi- Al conversion capability.

Transcrypt

This is a newly emerging Python to JS translator. Transcrypt makes an impressive commitment to the quality level of the code it generates. First, it retains the original Python code structure as much as possible, including multiple inheritance and lambda expressions. Python source code can also directly call objects in the namespace in JavaScript. If you try to access document. getElementById in Python, the converted code will also switch to document. getElementById in JavaScript.

According to the instructions, Transcrypt uses the abstract syntax tree module of CPython to complete these translation tasks. It can program access to its own code parsing methods based on Python. Although the project is still in alpha testing, it has shown amazing appeal.

Jiphy

The so-called Jiphy represents "JavaScript inbound, Python outbound"-that is, two-way conversion between the two. In addition, code from both languages can be mixed before being converted to another language.

Jiphy currently has the biggest shortcoming in that it only supports some feature sets of Python. Class and default parameters are not supported yet, but the decorator and exception mechanism can be used normally. This is mainly because Jiphy insisted on line-to-line direct translation between the source code and the target code, but its developers began to focus on the new features in ES6, it aims to include more advanced Python functions in support.

Brython

Maybe one day, when WebAssembly is conceived as a reality, we will be able to choose any preferred language for Web development. But Brython has his own understanding of this -- or at least applies to Python 3 --: Why?

Through a set of JavaScript libraries, Brython simulates all the keywords in Python 3 and most of the built-in plug-ins, so as to achieve the goal of using Python 3 as the client Web programming solution. Scripts compiled by Python can be directly added to the web page, while Brython also supports a set of advanced Python module interfaces (browser) for execution collaboration with DOM, and the browser can usually be directly completed in JavaScript.

However, Brython also imposes restrictions on JavaScript code by browsers-for example, it does not support processing local file systems.

RapydScript

RapydScript promises to "make Python JavaScript Code no longer bad ." This project is similar to CoffeeScript in concept: code is written in Python form, JavaScript code is generated, and the best features of both are used at the same time. Python has clear syntax rules. In JavaScript, it has anonymous functions, DOM operations, and can use existing JavaScript libraries such as jQuery or Node. js kernels.

Articles you may be interested in:
  • Convert a dictionary to its json string in python
  • Python converts the json format to a text or SQL File

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.